如何仅显示来自 aws s3 ls 命令的文件? [英] How to display only files from aws s3 ls command?

查看:29
本文介绍了如何仅显示来自 aws s3 ls 命令的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 aws cli 使用以下命令列出 s3 存储桶中的文件 (文档):

I am using the aws cli to list the files in an s3 bucket using the following command (documentation):

aws s3 ls s3://mybucket --recursive --human-readable --summarize

这个命令给了我以下输出:

This command gives me the following output:

2013-09-02 21:37:53   10 Bytes a.txt
2013-09-02 21:37:53  2.9 MiB foo.zip
2013-09-02 21:32:57   23 Bytes foo/bar/.baz/a
2013-09-02 21:32:58   41 Bytes foo/bar/.baz/b
2013-09-02 21:32:57  281 Bytes foo/bar/.baz/c
2013-09-02 21:32:57   73 Bytes foo/bar/.baz/d
2013-09-02 21:32:57  452 Bytes foo/bar/.baz/e
2013-09-02 21:32:57  896 Bytes foo/bar/.baz/hooks/bar
2013-09-02 21:32:57  189 Bytes foo/bar/.baz/hooks/foo
2013-09-02 21:32:57  398 Bytes z.txt

Total Objects: 10
   Total Size: 2.9 MiB

然而,这是我想要的输出:

However, this is my desired output:

a.txt
foo.zip
foo/bar/.baz/a
foo/bar/.baz/b
foo/bar/.baz/c
foo/bar/.baz/d
foo/bar/.baz/e
foo/bar/.baz/hooks/bar
foo/bar/.baz/hooks/foo
z.txt

如何省略日期、时间和文件大小以仅显示文件列表?

How can I omit the date, time and file size in order to show only the file list?

推荐答案

您不能仅使用 aws 命令来执行此操作,但您可以轻松地将其通过管道传输到另一个命令以去除该部分你不想要.您还需要删除 --human-readable 标志以使输出更易于处理,以及 --summarize 标志以删除最后的摘要数据.

You can't do this with just the aws command, but you can easily pipe it to another command to strip out the portion you don't want. You also need to remove the --human-readable flag to get output easier to work with, and the --summarize flag to remove the summary data at the end.

试试这个:

aws s3 ls s3://mybucket --recursive | awk '{print $4}'

考虑文件名中的空格:

aws s3 ls s3://mybucket --recursive | awk '{$1=$2=$3=""; print $0}' | sed 's/^[ 	]*//'

这篇关于如何仅显示来自 aws s3 ls 命令的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆