简体   繁体   English

在Linux中按时间戳排序文件直到毫秒

[英]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. 我正在尝试通过SFTP从辅助服务器中提取文件,然后处理这些文件。 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. 这些文件在辅助服务器上创建的时间不到1秒,因此所有文件都具有相同的创建时间戳。假设在辅助服务器上创建了4个文件(1.txt,2.txt,3.txt和4.txt)。服务器以相同的顺序。 However when I run ls -ltr command on the server , I get out put as follows: 但是,当我在服务器上运行ls -ltr命令时,输出如下:

在此处输入图片说明

Also when I tried to sort files based on time till milliseconds using the command ls --full-time -ltr , I got the following output: 同样,当我尝试使用ls --full-time -ltr命令基于毫秒前的时间对文件进行排序时,我得到以下输出:

在此处输入图片说明

The above output is wrong as file 1 was created before remaining files. 上面的输出是错误的,因为文件1是在剩余文件之前创建的。 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. 由于时间戳甚至长达几毫秒都是相同的,因此我认为正确排序这些时间戳的唯一方法是使用每个文件的inode。 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. 这是我的示例交互,我按此顺序同时创建了文件1、3、4、2。
Using ls --full-time -lt doesn't work. 使用ls --full-time -lt无效。 But using ls --full-time -i | sort -u 但是使用ls --full-time -i | sort -u ls --full-time -i | sort -u lists these files in the order they were created. ls --full-time -i | sort -u按创建顺序列出这些文件。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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