Awesome Shell Power: */.

2007-04-17

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 */.

About these ads

4 Responses to “Awesome Shell Power: */.”

  1. YAJer Says:

    You don’t really need that trailing dot

    ls -d */

    or

    echo */ | fmt

    etc…

  2. drj11 Says:

    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.

  3. afrobeard Says:

    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?

  4. drj11 Says:

    find . -type d -print


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: