Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Basic Storage Commands with gsutil
📖 Scenario: You are working as a cloud assistant helping a small company manage their files in Google Cloud Storage. You need to create a storage bucket, upload files, list the files, and finally delete the bucket when done.
🎯 Goal: Learn how to use basic gsutil commands to create a bucket, upload files, list files, and delete a bucket in Google Cloud Storage.
📋 What You'll Learn
Create a storage bucket named exactly my-test-bucket-12345
Upload a file named example.txt to the bucket
List the files inside the bucket
Delete the bucket after cleaning up
💡 Why This Matters
🌍 Real World
Cloud storage is used to keep files safe and accessible from anywhere. Knowing how to manage buckets and files with gsutil helps you organize and control your cloud data.
💼 Career
Many cloud jobs require managing storage resources. Knowing gsutil commands is a basic skill for cloud administrators and developers working with Google Cloud.
Progress0 / 4 steps
1
Create a storage bucket
Use the gsutil mb command to create a bucket named my-test-bucket-12345 in the default location.
GCP
Hint
Remember, mb means 'make bucket'. The bucket name must start with gs://.
2
Upload a file to the bucket
Use the gsutil cp command to upload a file named example.txt from your local machine to the bucket my-test-bucket-12345.
GCP
Hint
Use cp to copy files. The source is example.txt, the destination is the bucket URL.
3
List files in the bucket
Use the gsutil ls command to list all files inside the bucket my-test-bucket-12345.
GCP
Hint
ls lists files. Use it with the bucket URL to see contents.
4
Delete the bucket
First, delete all files inside the bucket using gsutil rm, then delete the bucket itself using gsutil rb. Use the bucket name my-test-bucket-12345.
GCP
Hint
Use rm with ** to delete all files, then rb to remove the bucket.
Practice
(1/5)
1. What does the gsutil ls gs://my-bucket command do?
easy
A. Lists all files and folders inside the bucket named 'my-bucket'.
B. Deletes the bucket named 'my-bucket'.
C. Creates a new bucket named 'my-bucket'.
D. Copies files from 'my-bucket' to your local machine.
Solution
Step 1: Understand the 'ls' command in gsutil
The 'ls' command lists contents of a bucket or folder in Google Cloud Storage.
Step 2: Apply the command to the bucket 'my-bucket'
Running gsutil ls gs://my-bucket shows all files and folders inside that bucket.
Final Answer:
Lists all files and folders inside the bucket named 'my-bucket'. -> Option A
Quick Check:
gsutil ls lists bucket contents = C [OK]
Hint: Remember: 'ls' means list contents of bucket or folder [OK]
Common Mistakes:
Confusing 'ls' with 'rm' which deletes files
Thinking 'ls' creates buckets
Assuming 'ls' copies files
2. Which of the following is the correct syntax to copy a local file named photo.jpg to a bucket gs://images-bucket using gsutil?
easy
A. gsutil copy photo.jpg gs://images-bucket
B. gsutil cp gs://images-bucket photo.jpg
C. gsutil cp photo.jpg gs://images-bucket
D. gsutil upload photo.jpg gs://images-bucket
Solution
Step 1: Identify the correct gsutil command for copying
The command to copy files is gsutil cp, followed by source then destination.
Step 2: Place source and destination correctly
Local file is source (photo.jpg), bucket is destination (gs://images-bucket), so syntax is gsutil cp photo.jpg gs://images-bucket.
Final Answer:
gsutil cp photo.jpg gs://images-bucket -> Option C
Quick Check:
cp source destination = A [OK]
Hint: Copy command is 'cp' with source first, then destination [OK]
Common Mistakes:
Swapping source and destination order
Using 'copy' instead of 'cp'
Using 'upload' which is not a gsutil command
3. What will be the output of the command gsutil ls gs://my-bucket/folder/ if the folder contains files file1.txt and file2.txt?
medium
A. gs://my-bucket/folder/file1.txt\ngs://my-bucket/folder/file2.txt
B. file1.txt\nfile2.txt
C. gs://my-bucket/file1.txt\ngs://my-bucket/file2.txt
D. No output, command will fail
Solution
Step 1: Understand gsutil ls output format
The 'gsutil ls' command lists full paths of files including bucket and folder names.
Step 2: Apply to files inside 'folder/'
Files inside 'folder/' will be listed with full path prefix: gs://my-bucket/folder/file1.txt and gs://my-bucket/folder/file2.txt.
Final Answer:
gs://my-bucket/folder/file1.txt
gs://my-bucket/folder/file2.txt -> Option A
Quick Check:
gsutil ls shows full gs:// paths = B [OK]
Hint: gsutil ls shows full gs:// path, not just file names [OK]
Common Mistakes:
Expecting only file names without bucket path
Confusing folder path with bucket root
Assuming command fails if folder exists
4. You run gsutil rm gs://my-bucket/data.csv but get an error saying the file does not exist. What is the most likely cause?
medium
A. You need to add '-r' flag to remove a single file.
B. You used 'rm' instead of 'delete' command.
C. The bucket 'my-bucket' does not exist.
D. The file 'data.csv' is not in the bucket 'my-bucket'.
Solution
Step 1: Understand the error message about file not existing
The error means the specified file path is not found in the bucket.
Step 2: Check command and flags correctness
'rm' is the correct command to remove files; '-r' is only for recursive folder deletion, not needed for single files.
Final Answer:
The file 'data.csv' is not in the bucket 'my-bucket'. -> Option D
Quick Check:
File missing causes error, not command or flags [OK]
Hint: Check file path exists before removing [OK]
Common Mistakes:
Thinking 'rm' is wrong command
Adding '-r' unnecessarily for single files
Assuming bucket missing causes file not found error
5. You want to delete an empty bucket named gs://temp-bucket. Which command should you use to safely remove it?
hard
A. gsutil cp gs://temp-bucket ./
B. gsutil rb gs://temp-bucket
C. gsutil delete gs://temp-bucket
D. gsutil rm gs://temp-bucket
Solution
Step 1: Identify the command to remove buckets
The command to remove a bucket is gsutil rb (remove bucket).
Step 2: Confirm bucket is empty before removal
Bucket must be empty to remove; if not, remove files first. Then run gsutil rb gs://temp-bucket.
Final Answer:
gsutil rb gs://temp-bucket -> Option B
Quick Check:
Remove bucket = rb command [OK]
Hint: Use 'rb' to remove empty buckets safely [OK]