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

发布于 2024-08-29 11:55:19 字数 455 浏览 3 评论 0原文

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>

如何选择以 00 ... XX 结尾且文件集最新日期的所有存档文件?

日期和时间未排序。

bash、正则表达式?

谢谢!

Amazon "s3cmd ls" takes like this output:

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 ?

Date and time is not sorted.

Bash, regexp ?

Thanx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

薄荷梦 2024-09-05 11:55:19
s3cmd ls s3://bucket/path/ | sort -k1,2

这将按日期升序排序。

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

This will sort by date ascending.

离不开的别离 2024-09-05 11:55:19
DATE=$(s3cmd ls | sort -n | tail -n 1 | awk '{print $1}')
s3cmd ls | grep $DATE 

按数字排序应将最年轻的日期放在最后。 tail -n1 获取最后一行,awk 剪切第一个单词,即日期。用它来获取该日期的所有条目。

但也许我不明白这个问题 - 所以你必须重新表述。您告诉我们“日期和时间未排序”并提供了一个对它们进行排序的示例 - 您要求最新日期,但所有条目都具有相同的日期。

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.

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.

橘虞初梦 2024-09-05 11:55:19

尝试

此命令语法为 s3 ls s3:// 存储桶/文件的路径 | sort

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

最后会按照日期降序排序

Try

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

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

It will sort in the descending date at last

月依秋水 2024-09-05 11:55:19

只需附加 | sort 到您的 s3cmd ls 命令以按日期排序。最新的文件将出现在命令行的正上方。

s3cmd ls s3://path/to/file | s3cmd ls s3://path/to/file |排序

Simply append | sort to your s3cmd ls command to sort by date. The most recent file will appear right above your command line.

s3cmd ls s3://path/to/file | sort

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文