Server Fault is a question and answer site for system and network administrators. 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

How can I sort the /dev directory by type and major and minor device number when doing ls -l?

The best way I've found so far is:

ls -l /dev | sort -k 1.1,1.2 -k 5n -k 6n | less

Is there a better way?

share|improve this question
It seems to sort correctly, is there some issue that needs solving? – casualcoder Feb 16 '10 at 3:17
I didn't say it doesn't work. I want to know if there's a better way. – Dennis Williamson Feb 16 '10 at 4:01
It is fairly compact, you have marshalled the sort arguments as necessary and the whole thing could be put into a shell alias for quick access if you ever wanted to use it frequently. Imagine writing an awk, Perl or other language script in its place. – casualcoder Feb 17 '10 at 3:05
The code of ls is free to be modified, the option could be added. – ringø Oct 5 '10 at 15:46
up vote 2 down vote accepted

Three processes is already pretty slim. You'll only make it slimmer if you could persuade ls to do this complex sorting itself, which you can't, or if you could dispense with the pager, which is irrelevant to what you're asking.

So I'd say no, no better way.

(The options to sort don't have any redundant fluff in them either.)

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.