Wednesday, March 16, 2011

Sorting the output from 'ls' command when filenames have numbers

Jai Srila Prabhupada.

Many times filenames contain numbers of arbitrary length - file1, file2, ..., file9, file10, file11, ..., file19, file20, file21, ... so on. When we run the 'ls' command, the output is sorted based on dictionary order and not in the way shown above.

Use the following command:
ls | sort -V

Note that we are calling 'ls' without any arguments, otherwise it won't work.

Jaya Sathguru Bhagawan Sri Sridhara Swamy Maharaja.

No comments:

Post a Comment