Can ls be made to only list directories?

Alex Martelli staff at cadlab.sublink.ORG
Fri Sep 7 01:59:38 AEST 1990


shwake at raysnec.UUCP (Ray Shwake) writes:

>Create a shell script - call it dirs - then run "dirs *"

>for i in `file $* | fgrep directory | sed 's/\([^:]*\):.*/\1/'`
>do
>	/bin/echo "$i \c"	# feel free to modify for built-in echo
>done
>echo

Just a little observation - 's/:.*//' seems a tad simpler than the
sed command suggested (I use it all the time for similar purposes,
e.g. "file * | fgrep text | sed 's/:.*//' | xargs ls -l", interactively,
to long-list text-files only).  Either will give problems on filenames 
with embedded colons, but my suggestion's a bit easier to fix - just
place a tab between the colon and the dot.

-- 
Alex Martelli - CAD.LAB s.p.a., v. Stalingrado 45, Bologna, Italia
Email: (work:) staff at cadlab.sublink.org, (home:) alex at am.sublink.org
Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; 
Fax: ++39 (51) 366964 (work only; any time of day or night).



More information about the Comp.unix.questions mailing list