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?

link|improve this question
feedback

1 Answer

up vote 3 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.

link|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
feedback

Your Answer

 
or
required, but never shown

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