Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a rather strict set of specs for a directory listing that I need:

  1. It must list the directories in the current directory
  2. It must list purely the basename (no "./", no trailing slash)
  3. It mustn't error if there are none (and mustn't print an error to std{out,err})
  4. It must be very lightweight
  5. It must work under tcsh

I've got something working like this:

find -maxdepth 1 -mindepth 1 -type d -printf '%f\n'

But I can't help feeling that using "find" is overkill. I tried to do something with ls -d */, but I couldn't figure out how to get it not error (or appear to not error).

Any suggestions?

share|improve this question
How do you need the output? ls-style or one per line? – Dennis Mar 26 '13 at 14:32
This is for a tcsh completion, which I think means either will work (I can't use the standard directory completion, for reasons I won't go into right now). – spookypeanut Mar 26 '13 at 16:48
up vote 1 down vote accepted

Personally, I'd say the find command is the way to go.

The ls -d approach has two problems right now:

  • It shows an error on empty directories.
  • It prints trailing slashes.

Both are fixable. tr can take care of the slashes, and you need redirection to get rid of error messages:

( ls -d */ | tr -d / > /dev/tty ) > & /dev/null

See man tcsh for further information.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.