简体   繁体   English

计算使用aws cli命令递归复制的文件数

[英]count the number of files copied recursively using aws cli commands

Could someone help me with the command to count the number of files only copied from one parent object to another parent object. 有人可以通过命令帮助我计算仅从一个父对象复制到另一个父对象的文件数。 For example 例如

1. src/folder1/some1.txt    
2. src/folder1/folder1_1/some1.txt
3. src/folder2/folder2_1/some2.txt
4. src/folder4/folder4_2/some3.txt
5. src/folder4/folder4_1/some4.txt

copy over them to dest folder 复制到dest文件夹

So, when I do 所以,当我这样做

aws s3 cp s3://src/* s3://dest/ --recursive aws s3 cp s3:// src / * s3:// dest /-递归

I need a count of the number of files copied. 我需要计算复制文件的数量。

Lets say we have mp3 files in a S3 bucket with the following path: bucket-name/path/to/files Then the cmd aws s3 ls bucket-name/path/to/files --recursive | grep 'mp3' | wc -l 假设我们在S3存储桶中具有mp3文件,其路径如下: bucket-name/path/to/files然后cmd aws s3 ls bucket-name/path/to/files --recursive | grep 'mp3' | wc -l aws s3 ls bucket-name/path/to/files --recursive | grep 'mp3' | wc -l aws s3 ls bucket-name/path/to/files --recursive | grep 'mp3' | wc -l will output the count of all mp3 files in that path even if they are present within directories. aws s3 ls bucket-name/path/to/files --recursive | grep 'mp3' | wc -l将输出该路径中所有mp3文件的计数,即使它们存在于目录中。

The simplest way I can think of is to rely on the fact that cp -v prints each file that it copies in a format like `source' -> `dest' : 我能想到的最简单的方法是依靠cp -v`source' -> `dest'这样的格式打印它复制的每个文件的事实:

cp --recursive --verbose s3://src/* s3://dest/ | grep -F '->' | wc -l

grep will output something for each line where -> is found, and wc will count the lines, which will give you the total number of copies made. grep会为找到->每一行输出一些内容,而wc会对行进行计数,这将为您提供已复制的总数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM