chetan
chetan

Reputation: 1395

Sort files on timestamp till milliseconds in Linux

I am trying to pick up files from a secondary server via SFTP and then processing the files. The files are created on secondary server in less than 1 second and as a result all the files have same timestamp for creation.Lets suppose 4 files (1.txt , 2.txt, 3.txt and 4.txt) are created on secondary server in the same orders. However when I run ls -ltr command on the server , I get out put as follows:

enter image description here

Also when I tried to sort files based on time till milliseconds using the command ls --full-time -ltr , I got the following output:

enter image description here

The above output is wrong as file 1 was created before remaining files. Can somebody please help on how to get the correct sorted list here.

Upvotes: 1

Views: 4936

Answers (1)

Saeed
Saeed

Reputation: 152

Since, the timestamps are same even up to milliseconds, I think the only way to sort these properly is using inode of each file. I think this solution should be able to work in your scenario.

Here is my example interaction, I created files 1, 3, 4, 2 in this sequence at the same time.
Using ls --full-time -lt doesn't work. But using ls --full-time -i | sort -u lists these files in the order they were created. enter image description here

Upvotes: 1

Related Questions