简体   繁体   中英

How to sort output of “s3cmd ls”

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!

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

这将按日期升序排序。

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.

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

Simply append | sort | 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

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