I have a requirement to identify sequence gap in a set of files. Sequence starts at FILENAME_0001 and ends at FILENAME_9999. After this the sequence is restarted from 0001.
To implement a proper sequence check I used ls -rt to pick the files in order of modified time and the compared with the previous files sequence number. If the previous file was 9999 I check whether the next one is 0001 (to accommodate the sequence reset).
Recently I came across a scenario where files were listed in the below order:
FILENAME_0001
FILENAME_0002
FILENAME_0005
FILENAME_0003
FILENAME_0004
FILENAME_0006
FILENAME_0007
This was because files 3, 4 & 5 had the same modified time to the second. Only the millisecond was different. So I am guessing ls -rt considers only upto the seconds. Could someone suggest a workaround?