Manage Storage Configuration using gsutil

실습 10분 universal_currency_alt 무료 show_chart 입문
info 이 실습에는 학습을 지원하는 AI 도구가 통합되어 있을 수 있습니다.
이 콘텐츠는 아직 휴대기기에 최적화되지 않음
최상의 경험을 위해 데스크톱 컴퓨터에서 이메일로 전송된 링크를 사용하여 방문하세요.

Google Cloud self-paced labs logo

Overview

In this lab, you will use gsutil to create a bucket and perform operations on objects. gsutil is a Python application that lets you access Cloud Storage from the command line. The gsutil tool has commands such as mb and cp to perform operations. Each command has a set of options that are used to customize settings further.

What you'll learn to do

  • Create a bucket
  • Copy files from a local folder to a bucket
  • Synchronize the contents of the local folder with the contents of the bucket
  • Change access control permissions on objects

Setup and requirements

  • Labs are timed and cannot be paused. The timer starts when you click Start Lab.
  • The included cloud terminal is preconfigured with the gcloud SDK.
  • Use the terminal to execute commands and then click Check my progress to verify your work.

Get the sample code and set variables

  1. In the cloud terminal session, execute the following command to download sample data for this lab from a git repository:
git clone https://github.com/GoogleCloudPlatform/training-data-analyst
  1. Change to the blogs directory:
cd training-data-analyst/blogs
  1. Set some environment variables:
PROJECT_ID=`gcloud config get-value project` BUCKET=${PROJECT_ID}-bucket

Task 1. Create a bucket

  • Run the following command to create a bucket with multi-regional storage class:
gsutil mb -c multi_regional gs://${BUCKET}

The gsutil mb command is used to create a new Google Cloud Storage bucket. The -c flag allows you to specify the storage class for the bucket, and the multi_regional storage class is designed for data that needs to be available in multiple regions (ideal for high availability and low-latency access).

Click Check my progress to verify the objective.

Create a bucket

Task 2. Upload objects to your bucket

  • Run the following to copy the endpointslambda object to your bucket:
gsutil -m cp -r endpointslambda gs://${BUCKET}

The gsutil -m cp -r command is used to copy files or directories to a Google Cloud Storage bucket

If you have a large number of files to transfer, you might want to use the -m option, to perform a parallel (multi-threaded/multi-processing) copy for faster performance. The -r option allows gsutil to recurse through directories.

Click Check my progress to verify the objective.

Upload objects to your bucket

Task 3. List objects

  • To list objects in your bucket, execute the following command:
gsutil ls gs://${BUCKET}/*

This command lists all objects (files and directories) inside a specific bucket in Google Cloud Storage, including any nested objects.

Task 4. Sync changes with bucket

  1. Use the following mv command to rename and rm command to delete some files:
mv endpointslambda/Apache2_0License.txt endpointslambda/old.txt rm endpointslambda/aeflex-endpoints/app.yaml
  1. Now synchronize the local changes with the bucket:
gsutil -m rsync -d -r endpointslambda gs://${BUCKET}/endpointslambda

In this command, the -d option deletes files from the target if they're missing in the source (in this case, it deletes app.yaml from the bucket). The -r option runs the command recursively on directories.

  1. To verify that the bucket is now in sync with your local changes, list the files in the bucket again:
gsutil ls gs://${BUCKET}/*

Click Check my progress to verify the objective.

Sync changes with bucket

Task 5. Make objects public

  1. To allow public access to all files under the endpointslambda folder in your bucket, execute the following command:
gsutil -m acl set -R -a public-read gs://${BUCKET}

The above command is used to set access control lists (ACLs) on Cloud Storage buckets or objects. This makes all the objects in a bucket publicly readable.

The -m flag enables parallel processing, which means multiple operations (like setting ACLs on many files) will be executed simultaneously, speeding up the process. The -R flag applies the ACL recursively to all objects inside the bucket. Without this, it would only apply to the bucket itself, not its contents.

  1. To confirm files are viewable by the public, open the following link in a new incognito or private browser window, replacing <your-bucket-name> with the full name of your bucket, not the environment variable:
http://storage.googleapis.com/<your-bucket-name>/endpointslambda/old.txt

This URL uses the Cloud Storage API link to view the object without authentication. Learn more about accessing public data from the Accessing public data documentation.

Task 6. Copy with different storage class

gsutil cp -s nearline ghcn/ghcn_on_bq.ipynb gs://${BUCKET}

The gsutil cp command is used to copy files from one location to another, either within Cloud Storage or from a local file system to Cloud Storage and -s flag specifies the storage class for the file being uploaded.

Click Check my progress to verify the objective.

Copy with different storage class

Task 7. Check storage classes

  1. Run the following to check the storage classes and view other detailed information about the objects in your bucket:
gsutil ls -Lr gs://${BUCKET} | more
  1. Press the space key to continue viewing the rest of the command's output.

The output shows that the ghcn_on_bq.ipynb object has NEARLINE storage class while the other objects have MULTI_REGIONAL storage class.

Output:

gs://qwiklabs-xxx-xxxxxxxxxxxxxxxx-bucket/ghcn_on_bq.ipynb: Creation time: Tue, 13 Aug 2019 20:19:27 GMT Update time: Tue, 13 Aug 2019 20:19:27 GMT Storage class: NEARLINE Content-Length: 980176 Content-Type: application/octet-stream ... gs://qwiklabs-xxx-xxxxxxxxxxxxxxxx-bucket/endpointslambda/: gs://qwiklabs-xxx-xxxxxxxxxxxxxxxx-bucket/endpointslambda/README.md: Creation time: Tue, 13 Aug 2019 20:03:29 GMT Update time: Tue, 13 Aug 2019 20:15:43 GMT Storage class: MULTI_REGIONAL Content-Length: 452 Content-Type: text/markdown ...
  1. You can use Ctrl + c to return to the command line.

Congratulations

You have now learned how to perform operations on Cloud Storage buckets and objects!

Next steps/learn more

For complete information about the gsutil command-line options, see:

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated May 21, 2025

Lab Last Tested May 21, 2024

Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

시작하기 전에

  1. 실습에서는 정해진 기간 동안 Google Cloud 프로젝트와 리소스를 만듭니다.
  2. 실습에는 시간 제한이 있으며 일시중지 기능이 없습니다. 실습을 종료하면 처음부터 다시 시작해야 합니다.
  3. 화면 왼쪽 상단에서 실습 시작을 클릭하여 시작합니다.

시크릿 브라우징 사용

  1. 실습에 입력한 사용자 이름비밀번호를 복사합니다.
  2. 비공개 모드에서 콘솔 열기를 클릭합니다.

콘솔에 로그인

    실습 사용자 인증 정보를 사용하여
  1. 로그인합니다. 다른 사용자 인증 정보를 사용하면 오류가 발생하거나 요금이 부과될 수 있습니다.
  2. 약관에 동의하고 리소스 복구 페이지를 건너뜁니다.
  3. 실습을 완료했거나 다시 시작하려고 하는 경우가 아니면 실습 종료를 클릭하지 마세요. 이 버튼을 클릭하면 작업 내용이 지워지고 프로젝트가 삭제됩니다.

현재 이 콘텐츠를 이용할 수 없습니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

감사합니다

이용할 수 있게 되면 이메일로 알려드리겠습니다.

한 번에 실습 1개만 가능

모든 기존 실습을 종료하고 이 실습을 시작할지 확인하세요.

시크릿 브라우징을 사용하여 실습 실행하기

이 실습을 실행하는 가장 좋은 방법은 시크릿 모드 또는 시크릿 브라우저 창을 사용하는 것입니다. 개인 계정과 학생 계정 간의 충돌로 개인 계정에 추가 요금이 발생하는 일을 방지해 줍니다.