5

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?

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

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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