Reputation: 721
I need to list the files on Directory. But only true files, not the folders. Just couldn't find a way to test if the file is a folder or a directory....
Could some one provide a pice o script for that?
Thanks
Upvotes: 0
Views: 5071
Reputation: 11
You can use ls -l | grep ^d -v
to realize what you want. I tested it in Redhat 9.0, it lists only the true files, including the Hidden Files.
If u want to get a list the folders on Directory. But only folders, not the true files. You can use ls -l | grep ^d
Upvotes: 0
Reputation: 8236
In bash
shell test -f $file
will tell you if $file is a file:
if test -f $file; then echo "File"; fi
Upvotes: 0
Reputation: 86333
How about using find
?
To find regular files in the current directory and output a sorted list:
$ find -maxdepth 1 -type f | sort
To find anything that is not a directory (Note: there are more things than just regular files and directories in Unix-like systems):
$ find -maxdepth 1 ! -type d | sort
Upvotes: 2