Non-standard sorting of the ls output

lsoutputsort

I usually include a date in the filename so that files and directories are listed in chronological order when I use the ls command, e.g. 2015-08-29_letter_to_santa.txt.

A drawback is that tab-completion is hampered. For the example above, if I want to open the letter to santa, I first need to get through the date before I can swiftly tab-complete the rest of the filename. This is annoying when many filenames start with a date.

I would like to be able to name the file something like letter_to_santa.2015-08-29.txt but still have ls output the files sorted by the date appearing in the filename. Any ideas of how to accomplish this, and at the same time preserving the colourful output that ls produces?

For the sake of being specific, let's assume that a filename is on the format basename.date.extension and . is used exactly twice in the filename.

Best Answer

try

 ls | sort -t. -k2 | while read f
 do
    ls "$f"
 done

I am assuming you have plain ordinary unix file without funny char in name.

Related Question