I need to create a file list which display the file name in ascending order. My file name has file pattern: FILE.YYYYMMDD.XXX
For example:
$ ls -ltr
-rwxr-xr-x. 1 honle 1036 Apr 14 2020 FILE.20200102.001
-rwxr-xr-x. 1 honle 426832 Apr 14 2020 FILE.20200102.002
-rwxr-xr-x. 1 honle 426832 Apr 14 2020 FILE.20200102.003
-rwxr-xr-x. 1 honle 426832 Apr 10 2020 FILE.20200110.001
-rw-r--r--. 1 honle 426832 Apr 14 22:50 FILE.20200220.001
-rwxr-xr-x. 1 honle 1036 Apr 15 16:30 FILE.20200110.001
Noted for input why FILE.20200120.002 before FILE.20200220.001. FILE.20200120.002 was processed and coming to current dir before FILE.20200220.001. That is why i need to sort it based on the YYYYMMDD.XXX filename pattern.
Desired output:
FILE.20200102.001
FILE.20200102.002
FILE.20200102.003
FILE.20200110.001
FILE.20200120.002
FILE.20200220.001
The time file was created is not in order so I can't use ls -ltr. Any idea how I can sort them? I am using Linux.
Thanks
If the issue is to get the filenames in a single column rather than in the multi-column format that ls produces, then you may use the -1 ("minus one") option to ls:
ls -1
The filenames would be sorted by name.
printf '%s\n' FILE.*
Assuming that the pattern FILE.* matches all relevant filenames, and nothing else, the above command would also print the filenames in lexicographical order, each on a line by itself, which seems to be what you want.
printf instead of a simple ls -l here? - terdon
ls -1, that would give a single column output. After re-reading, I'm a bit confused as to what the issue is. Possibly they are just over-specifying options... -t would sort on mtime, but just leave that option off then... - Kusalananda
-1, but that's why I'm waiting to see if they answer my comment about the ordering. Assuming the desired output is wrong, they just need ls -1, methinks. - terdon
FILE.20200120.002be beforeFILE.20200220.001? - terdonFILE.20200120.002afterFILE.20200220.001? - Arkadiusz Drabczykls -tto asklsto sort by "last modified" timestamp. It is unclear what order you want the files in. Sorted on filename, or sorted by modification time. - Kusalananda.HH.that you have mentioned a couple of times but that doesn't seem to be part of the actual filenames? - Kusalananda