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]


  • 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.

Howdy, Stranger!

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


In this Discussion