Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm not sure I am using ZSH's globbing correctly, but I thought ls *(/) would just list the dirctories under pwd, but it doesn't, it recursively lists all files under every directory under pwd (I got the statement from this list of useful zsh tips)

What would be right globbing for exclusively listing the directories under my current path?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

I suspect the problem is not the zsh globbing, but the ls default behavior, that when given a directory argument list the content of directory.

I suggest to try

ls -d -- <your-glob-here>

The best way to test your globs is with

printf '%s\n' <glob>
share|improve this answer
Another way to test globs with zsh is to tab-expand them. That’ll replace the glob with all matched paths. –  Jonas Wielicki Aug 13 at 10:36

Yet another way to achieve it is

 print *(/)


 echo *(/)


A bit more correct version (as noted by @Stéphane Chazelas) would be

print -rl -- *(/) 


echo -E - *(/)

to take care about spaces (-l), escape sequences (-r/-E) and leading hyphens (--/-) inside filenames.


Yet even more correct version is print -rN which additionally takes care of linebreaks inside filenames (linux allows them, windows doesn't) by separating the results with nulls, for example:

print -rN -- **/*(/) |xargs -0 -n10 chmod g+s

which recursively sets setguid bit - selectively addressing directories, as opposed to chmod -R g+s.


For huge trees this only processes a part of files (due to the limit on command line length) and silently leave the rest as is. The following commands can handle this situation:

find . -type d -print0 |xargs -0 -n10 chmod g+s
share|improve this answer
Should be print -rl -- *(/) or echo -E - *(/). Without -r/-E, print/echo expand escape sequences. The -l option to print prints one argument per line. See also -c (optionally with -a) to print in columns –  Stéphane Chazelas Aug 13 at 10:41
@Stéphane Chazelas Totally agree. I only use those without options if I created the files myself. That might not be secure enough, though. –  Antony Hatchkins Aug 13 at 12:19

@enzotib is right, and with that in mind, the command that lists directories under pwd in zsh is:

ls .(/)

share|improve this answer
No, ls .(/) lists the contents of the current directory (directories and non-directories alike). Since . is always a directory, this pattern is equivalent to .. –  Gilles Sep 1 '11 at 23:51
Thanks @Guilles, I think you are right. I'm happy to leave my answer in case anyone makes the same mistake. –  Amelio Vazquez-Reina Sep 1 '11 at 23:57

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.