Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Example list sorted from left to right.

DATA2
DATA4
FILE1
FILE3

Example list sorted from right to left.

FILE1
DATA2
FILE3
DATA4

How do I do this?

share|improve this question

1 Answer 1

up vote 6 down vote accepted
cat file | rev | sort | rev

Where file contains the content needing to be sorted.

$ cat file

DATA2
DATA4
FILE1
FILE3

Output:

$ cat file | rev | sort | rev

FILE1
DATA2
FILE3
DATA4

All it does is reverse each line before applying sort, then reverses each line back again.

share|improve this answer
1  
I see your title says "ls", if so, just replace cat file with ls –  Paul Nov 24 '11 at 5:35
    
+1 Did not know about rev. I have used bash on and off since 1992 and I still learn about new commands regularly. –  Nifle Nov 24 '11 at 8:05

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.