TensorFlow For Dummies
Book image
Explore Book Buy On Amazon
After you create a bucket with the gsutil utility on the Google Cloud Platform (GCP), you can upload files to it, thereby adding objects to the bucket. Similarly, you can download an object to your system as a file. Google makes these operations possible through the cp (copy) and mv (move) commands. Both commands transfer a source entity to a destination, but cp leaves the source entity in place while mv removes the source entity.

The best way to understand these commands is to look at some examples. The following command uploads a local file, hello.txt, to a bucket in Cloud Storage named gs://newbucket:

gsutil cp hello.txt gs://newbucket
Similarly, the following command moves hello.txt from gs://newbucket to the current directory on your development system. Note that mv removes hello.txt from the bucket:
gs mv gs://newbucket/hello.txt .
cp and mv accept many of the same flags as their counterparts in Linux and Unix. These flags include the following:
  • -r: Copy/move a directory and its contents
  • -L: Outputs a log file for each source entity of the copy/move
  • -e: Excludes symbolic links from the copy/move
For example, the following command moves the local mydir directory and its contents to firstbucket.
gsutil mv -r mydir gs://firstbucket
This command copies mydir and its contents from firstbucket to secondbucket:
gsutil cp -re gs://firstbucket/mydir gs://secondbucket
Because of the –e flag, gsutil won't copy any symbolic links from mydir to secondbucket.

About This Article

This article is from the book:

About the book author:

Matthew Scarpino has been a programmer and engineer for more than 20 years. He has worked extensively with machine learning applications, especially those involving financial analysis, cognitive modeling, and image recognition. Matthew is a Google Certified Data Engineer and blogs about TensorFlow at tfblog.com.

This article can be found in the category: