Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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. –  ring0 Oct 5 '10 at 15:46

1 Answer 1

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

 
discard

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.