How can I list directories with ls and sort them by their owner and group?

link|improve this question

50% accept rate
feedback

1 Answer

up vote 2 down vote accepted

Try this:

ls -l | awk '{print $3, $4, $8}' | sort

It will print the user name, the group name and the file name, provided that the file name doesn't contain spaces. Alternatively, you can type:

ls -l | awk '{print $3, $4, $0}' | sort

This will print the user name, group name and the full ls -l output, sorted by the user name first, then the group name, then whatever ls -l prints first.

Note that depending on your distribution, the actual column numbers may differ. I tried mine in SUSE and coreutils version 5.2.1.

There are probably better, more elaborate solutions, but this is the simplest one, and will work most of the time.

link|improve this answer
s/row numbers/column numbers/ – Dennis Williamson May 14 '10 at 11:20
Thanks, corrected. – petersohn May 20 '10 at 15:59
feedback

Your Answer

 
or
required, but never shown

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