如何对“s3cmd ls”输出进行排序

时间:2021-09-09 04:07:53

Amazon "s3cmd ls" takes like this output:

Amazon“s3cmd ls”的输出如下:

2010-02-20 21:01 1458414588   s3://file1.tgz.00<br>
2010-02-20 21:10 1458414527   s3://file1.tgz.01<br>
2010-02-20 22:01 1458414588   s3://file2.tgz.00<br>
2010-02-20 23:10 1458414527   s3://file2.tgz.01<br>
2010-02-20 23:20 1458414588   s3://file2.tgz.02<br>
<br>

How to select all files of archive, ending at 00 ... XX, with the latest date of fileset ?

如何选择所有存档文件,以00结束…XX,文件集的最新日期?

Date and time is not sorted.

日期和时间没有排序。

Bash, regexp ?

Bash,正则表达式?

Thanx!

谢谢!

3 个解决方案

#1


9  

DATE=$(s3cmd ls | sort -n | tail -n 1 | awk '{print $1}')
s3cmd ls | grep $DATE 

sorting as a number schould put youngest dates last. Tail -n1 takes the last line, awk cuts the first word which is the date. Use that to get all entries of that date.

把最年轻的日期排在最后。尾部-n1取最后一行,awk切掉第一个词,也就是日期。使用它获取该日期的所有条目。

But maybe I didn't understand the question - so you have to rephrase it. You tell us 'date and time is not sorted' and provide an example where they are sorted - you ask for the latest date, but all entries have the same date.

但也许我不理解这个问题,所以你必须重新措辞。您告诉我们“日期和时间没有排序”,并提供它们排序的示例——您询问最近的日期,但所有条目的日期都是相同的。

#2


9  

s3cmd ls s3://bucket/path/ | sort -k1,2

This will sort by date ascending.

这将按日期升序排序。

#3


0  

Try

试一试

This command syntax is s3 ls s3:// path of the bucket / files | sort

这个命令语法是s3 ls s3:// bucket / file |排序的路径

s3cmd ls s3://file1.tgz.00<br>  | sort

It will sort in the descending date at last

它最终将按降序排序

#1


9  

DATE=$(s3cmd ls | sort -n | tail -n 1 | awk '{print $1}')
s3cmd ls | grep $DATE 

sorting as a number schould put youngest dates last. Tail -n1 takes the last line, awk cuts the first word which is the date. Use that to get all entries of that date.

把最年轻的日期排在最后。尾部-n1取最后一行,awk切掉第一个词,也就是日期。使用它获取该日期的所有条目。

But maybe I didn't understand the question - so you have to rephrase it. You tell us 'date and time is not sorted' and provide an example where they are sorted - you ask for the latest date, but all entries have the same date.

但也许我不理解这个问题,所以你必须重新措辞。您告诉我们“日期和时间没有排序”,并提供它们排序的示例——您询问最近的日期,但所有条目的日期都是相同的。

#2


9  

s3cmd ls s3://bucket/path/ | sort -k1,2

This will sort by date ascending.

这将按日期升序排序。

#3


0  

Try

试一试

This command syntax is s3 ls s3:// path of the bucket / files | sort

这个命令语法是s3 ls s3:// bucket / file |排序的路径

s3cmd ls s3://file1.tgz.00<br>  | sort

It will sort in the descending date at last

它最终将按降序排序