Gsutil批量复制/移动文件

问题描述 投票:-2回答:2

是否可以使用gsutil命令批量复制或移动文件?例如,如果我要将100个文件从给定文件夹复制到另一个文件夹。

google-cloud-storage gsutil
2个回答
0
投票

尝试一下:

gsutil ls gs://bucketA | head -n 100 | shuf | gsutil cp -m -I gs://bucketB

这将获取bucketA中的文件列表,获取前100个项目,用shuf对其进行随机化,然后将它们传送到shuf中以复制到bucketB。 gsutil标志从-I读取文件列表。


0
投票

另一种实现方法是使用stdin。例如在Python中:

Client libraries

这会将前100个文件从GCS存储桶from google.cloud import storage storage_client = storage.Client() bucket_name = 'my_bucket' bucket = storage_client.get_bucket(bucket_name) blobs_to_move = [blob for blob in bucket.list_blobs(prefix="folder1/")] with storage_client.batch(): for blob in blobs_to_move[:100]: # copy to new destination new_blob = bucket.copy_blob(blob, bucket, "folder2/" + blob.name[8:]) # delete in old destination blob.delete() 中的folder1移动到my_bucket

© www.soinside.com 2019 - 2024. All rights reserved.