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?

link|improve this question

71% accept rate
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. – ring0 Oct 5 '10 at 15:46
feedback

1 Answer

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.)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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