简体   繁体   中英

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:

在此处输入图片说明

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

在此处输入图片说明

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.

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 ls --full-time -i | sort -u lists these files in the order they were created. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM