listing Directory chronologically based on part of file name

hi Everbody,

I had file names as shown

file_01_20101104.txt
file_01_20101105.txt
file_02_20101104.txt
file_01_20101205.txt
file_03_20101104.txt
file_02_20101105.txt

Now i want to list them based on the date in the file name as shown...

file_01_20101104.txt
file_02_20101104.txt
file_03_20101104.txt
file_01_20101105.txt
file_02_20101105.txt
file_01_20101205.txt

i cant do it by using the regular ls -ltr as it was sort in the chronologically based on the file creation time ....
can we do it using a single line UNIX command as i have to pass this command to another java program call...

Help is greatly appreciated....

Thanks in advance..

Reddy

Try:

ls | sort -nt_ -k3,3 -k2,2
1 Like

Thats Awesome...
Perfectly working..

Now can you please explain me the command issued using sort.....