如何使用gsutil计算存储分区文件夹中的文件数 [英] How to count number of file in a bucket-folder with gsutil
问题描述
是否可以计算存储分区文件夹中的文件数?
Is there an option to count the number of files in bucket-folders?
赞:
gsutil ls -count -recursive gs://bucket/folder
Result: 666 files
我只想比较文件总数 等于我服务器上的同步文件夹.
I just want an total number of files to compare the amount to the sync-folder on my server.
我没有在手册中得到它.
I don't get it in the manual.
推荐答案
gsutil 带有选项-l
(长清单)和-R
(递归清单)的ls命令将递归列出整个存储桶,然后最后产生所有对象的总数,包括文件和目录:>
The gsutil ls command with options -l
(long listing) and -R
(recursive listing) will list the entire bucket recursively and then produce a total count of all objects, both files and directories, at the end:
$ gsutil ls -lR gs://pub
104413 2011-04-03T20:58:02Z gs://pub/SomeOfTheTeam.jpg
172 2012-06-18T21:51:01Z gs://pub/cloud_storage_storage_schema_v0.json
1379 2012-06-18T21:51:01Z gs://pub/cloud_storage_usage_schema_v0.json
1767691 2013-09-18T07:57:42Z gs://pub/gsutil.tar.gz
2445111 2013-09-18T07:57:44Z gs://pub/gsutil.zip
1136 2012-07-19T16:01:05Z gs://pub/gsutil_2.0.ReleaseNotes.txt
... <snipped> ...
gs://pub/apt/pool/main/p/python-socksipy-branch/:
10372 2013-06-10T22:52:58Z gs://pub/apt/pool/main/p/python-socksipy-branch/python-socksipy-branch_1.01_all.deb
gs://pub/shakespeare/:
84 2010-05-07T23:36:25Z gs://pub/shakespeare/rose.txt
TOTAL: 144 objects, 102723169 bytes (97.96 MB)
如果您真的只想要总数,则可以将输出通过管道传递到tail
命令:
If you really just want the total, you can pipe the output to the tail
command:
$ gsutil ls -lR gs://pub | tail -n 1
TOTAL: 144 objects, 102723169 bytes (97.96 MB)
更新
gsutil现在有一个 du命令.这使得计数变得更加容易:
gsutil now has a du command. This makes it even easier to get a count:
$ gsutil du gs://pub | wc -l
232
这篇关于如何使用gsutil计算存储分区文件夹中的文件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!