0
0
GCPcloud~5 mins

Buckets and objects concept in GCP - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to store files like photos, videos, or documents in the cloud, you use buckets and objects. Buckets are like folders, and objects are the files inside them. This helps keep your data safe and easy to find.
When you want to save backups of your work files in the cloud.
When you need to share images or videos with your team securely.
When you want to store logs or data generated by your app.
When you want to keep large files accessible from anywhere.
When you want to organize files by project or type using folders.
Commands
This command creates a new bucket named 'example-bucket-12345' in Google Cloud Storage. Buckets hold your files (objects).
Terminal
gsutil mb gs://example-bucket-12345
Expected OutputExpected
Creating gs://example-bucket-12345/... Created bucket gs://example-bucket-12345/
This command lists all buckets in your Google Cloud project so you can see the bucket you just created.
Terminal
gsutil ls
Expected OutputExpected
gs://example-bucket-12345/
This command creates a simple text file named 'hello.txt' with a message inside. This file will be uploaded as an object.
Terminal
echo "Hello, Cloud Storage!" > hello.txt
Expected OutputExpected
No output (command runs silently)
This command uploads the file 'hello.txt' to the bucket 'example-bucket-12345'. The file becomes an object inside the bucket.
Terminal
gsutil cp hello.txt gs://example-bucket-12345/
Expected OutputExpected
Copying file://hello.txt [Content-Type=text/plain]... / [1 files][ 22.0 B/ 22.0 B] Operation completed over 1 objects.
This command lists all objects inside the bucket to confirm that 'hello.txt' was uploaded successfully.
Terminal
gsutil ls gs://example-bucket-12345/
Expected OutputExpected
gs://example-bucket-12345/hello.txt
Key Concept

If you remember nothing else from this pattern, remember: buckets are containers for your files, and objects are the files stored inside those buckets.

Common Mistakes
Trying to upload a file to a bucket that does not exist.
The upload fails because the bucket must exist before you can put files inside it.
Always create the bucket first using 'gsutil mb' before uploading files.
Using bucket names with uppercase letters or special characters.
Bucket names must be lowercase and follow naming rules, or creation will fail.
Use only lowercase letters, numbers, and dashes in bucket names.
Summary
Create a bucket using 'gsutil mb' to hold your files.
Upload files as objects into the bucket with 'gsutil cp'.
List buckets and objects with 'gsutil ls' to check your storage.