I probably know lots of tips and tricks about using /bin/sh
that are not widely enough known about.
Today’s shell tip: */.
It’s a shell pattern that expands to all the sub-directories of the current directory.
If you want to list all the names of the sub-directories in the current directory it’s a lot easier to type echo */.
than it is to type find . -name . -o -type d -print -prune
which is almost equivalent.
ls -ld */.
2007-05-21 at 18:13:04
You don’t really need that trailing dot
ls -d */
or
echo */ | fmt
etc…
2007-05-22 at 09:15:35
How true. Since this */. thing is a habit I picked up about 14 years ago, my only defence is that I must’ve needed the extra dot at the time. The only things I can think of are that either */ simply didn’t work with whatever shell I was using (which won’t have been bash) or that */ didn’t work with symbolic links to directories. I had a strong feeling about */ not working with symbolic links to directories, but I just tested it now (OS X, bash) and it works just fine.
2008-05-11 at 12:00:41
Nice tip, but note that its only for 1 level deepness.
For n levels the solution that I came across was:-
$ ls -R | grep ./
Is there some shorter way do this without invoking grep?
2008-05-11 at 14:23:33
find . -type d -print