about ls command - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

about ls command

[green]How can I get only files (excluding sub directories) of a path [italic]using ls command[/italic] . Any one pls help [/green]


  • nugentnugent Posts: 87Member

    I don't think the ls command has an option to check file type (under unix operating systems most things are treated as file, i.e. directories, block devices such ad hard drive partitions, sockets for communicating over the internet are all considered files). Check the man page to be sure (man 1 ls)

    But, you can use the file command to get what you want. A command such as

    find ./ -maxdepth 1 -type f

    will search in the current directory (./), will only process 1 level the filesystem tree (-maxdepth 1) and will only show regular files (-type f).


Sign In or Register to comment.