find . -name . -o -type d -print -prune
From there, I moved to using ls and grep:
ls -l | grep '^d'
I recently learned that the following shell pattern works just as well:
ls -ld */.
Tuesday, June 10, 2008
Quickly Find Subdir
I used to use a long-winded invocation of find with the prune option to non-recursively find all the directories in the current dir:
Subscribe to:
Post Comments (Atom)
3 comments:
shell expansions are also useful for showing all hidden files in the current directory like so:
ls -d .[^.]*
The "-d" prevents listing contents of hidden subdirectories. I have this aliased in my .bashrc as "l." -- and right beneath it now is your tip as "lsd"
The trouble with using '*', in general, is that it fails when there are too many entries in a directory or when any entries are too large. That's because the shell expands '*', and the shell has a certain length limitation. This is where iterator-type methods (like find(1)) shine.
If you're running zsh, you can run
ls -d *(/)
The / in the brackets tells the shell to only expand the directories that match *. You can do really wild things with zsh matching like...
print /etc/**/*(@)
to print all symlinks found under /etc.
Post a Comment