View Full Version : question about testing in shell programming
thungmail
04-04-2008, 05:28 PM
hi
How can i list files which are only folders in Unix
Tuan
rags_to_riches
04-04-2008, 07:04 PM
find . -type d -print
-print is the default. "." is also the default directory. So you can get away with
find -type d
("d" means of type "directory") or
find path -type d
Note that find is recursive -- it will show you subdirectories and so on too. If you just want a list of directories in the current directory, you can use something like this.
ls -l | grep ^d
That gives you the long filename listing, however, which you may not want. If you just want the filenames, you could use something like this:
for file in *; do [ -d "$file" ] && echo $file; done
I'm sure there's a cleaner way, but if there is, it escapes me at the moment.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.