gsutil Move, Copy, Archive Rename file/objects from Google Bucket
Today in this article we shall see how to use gsutil command-line tool to Archive,Move Or Copy File Google Cloud Storage Bucket gsutil
As we took deep dive into the previous article on gsutil, where we understood it is actually a Python command-line application that lets you access Cloud Storage.
You can use gsutil to perform a lot of operations including uploads and downloads etc. using HTTPS and transport-layer security (TLS) etc.
Today in this article, we will cover below aspects,
The gsutil
mv
the command allows you to move data between your local file system and the cloud, move data within the cloud, and move data between cloud storage providers
Prerequisites
- Create an account in the google cloud project.
- Install the Google Cloud SDK
Moving file with in a Google Bucket
We can easily use the mv command which lets you move from a source location to the target location. You can move data between local files and the cloud, move data between cloud storage providers or move data within the cloud.
Here default Move command is actually a combination of moving the file to a new location plus deleting of file from the source location.
Command Pattern
gsutil mv [source-gcs-path] [target-gcs-path]
Example
gsutil mv gs://thecodebuzz/load-from-gcutil/thecodebuzz.png gs://thecodebuzz/Archive
Moving file from one bucket to other bucket storage
Command Pattern
gsutil mv [source-gcs-path] [target-gcs-path]
Example
gsutil mv gs://thecodebuzz/load-from-gcutil/TheCodeBuzz.png gs://test-bucket-13/Archive
The above logic works for Jpeg or png or .text, pdf, or any file type.
List of contents/file of a bucket or folder
Please use the ls
command to list the contents at the top level of your bucket.
Command Pattern
gsutil ls [source-bucket-path]
Example
gsutil ls gs://thecodebuzz/
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.