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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2674117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:59:01  来源:igfitidea点击:

How to sort output of "s3cmd ls"

regexbashsortingls

提问by dba.in.ua

Amazon "s3cmd ls" takes like this output:

亚马逊“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!

谢谢!

采纳答案by user unknown

DATE=$(s3cmd ls | sort -n | tail -n 1 | awk '{print }')
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.

按数字排序应该把最年轻的日期放在最后。tail -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.

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

回答by Erik Kristensen

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

This will sort by date ascending.

这将按日期升序排序。

回答by Javeed Shakeel

Try

尝试

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

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

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

It will sort in the descending date at last

它将最后按降序排列