Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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'm aware of the ls option --group-directories-first but that's not exactly what I want to achieve.

The output should be: (sorted by name ASC)

  • Directories
  • Hidden Directories
  • Hidden Files
share|improve this question
up vote 4 down vote accepted

With GNU ls (the -U option to tell ls not to sort the file list is a GNU extension):

ls -lUd -- *(/) .*(/) .*(^/)

The problem though is that if any of those globs don't match, the command will be cancelled, so you could do:

myls() (
  setopt cshnullglob
  ls -lUd -- *(/) .*(/) .*(^/)

That emulates the csh behaviour whereby globs with no match expand to nothing as long as there's at least one glob that expands to something in the command.

Note that zsh globs never expand . and .., so those two will never be included.

share|improve this answer
works perfect, thanks so much... – makim Jun 23 '14 at 21:37
Don't think I've ever seen cshnullglob before - nice. – godlygeek Jun 23 '14 at 21:52
adding localoptions with it will scope the cshnullglob to the function. – llua Jun 24 '14 at 2:50
@llua, yes, but since we're executing a command anyway, we might as well limit the scope with a subshell (note the ( instead of {) – Stéphane Chazelas Jun 24 '14 at 7:08

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.