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 recently started using MinGW instead of Cygwin on my Windows 7 machine, and I am having a little issue with MinGW's ls. In Cygwin, ls has a --group-directories-first option that, obviously, causes directories to be listed before other file types. However, MinGW doesn't seem to have this option, and I can't find a substitute for it. Does one exist?

share|improve this question

This comes under the heading “a substitute for it”.  The following script will approximately emulate the behavior of ls –l with the difference that it groups subdirectories at the beginning of each directory listing.

#!/bin/sh -
    sed -n -e '1s/^/1#/p' -e '1n' \
        -e 's/^/#/' -e 's/^#d/2#d/' -e 's/^#/3#/' -e p \
        | cat -n | sort -n -k2 -k1 | sed 's/[^#]*#//'

if [ $# = 0 ]
    ls -l | sort_ls_output
    for arg
        if [ -d "$arg" ]
            echo "${arg}:"
            ls -l "$arg" | sort_ls_output
            ls -l "$arg"

It is a rough cut.  It doesn’t handle individual ordinary files (non-directories) on the command line the same way as ls –l does, and it doesn’t handle options (e.g., –a) at all.

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.