Google Cloud Storage(GCS) using CLI

Google Cloud Storage(GCS) using CLI

ยท

2 min read

Till now we did GCS lab using UI, Let's use CLI to create a bucket and Play with it accordingly

Shall we proceed!!!

Step 1 :- In the top right corner of the console, click on the CMD icon to open the Cloud Shell.

image.png

Step 2 :- Type out the command as follows.

gsutil --version

image.png

if you get popup like this click on Authorize

image.png

Step 3 :- Here's an example of how to create a bucket and give it a unique name for your bucket.

gsutil mb gs://[bucket-name]

mb - Make buckets

gs - Google storage

image.png

Your bucket will be created.

image.png

Step 4 :- If you want to list your bucket.

gsutil ls

image.png

Step 5 :- create a number of text files according to your wish.

touch command to create a text file.

touch 1.txt 2.txt

**ls **command to list files.

ls

image.png

Step 6 :- we will put text file into our bucket.

**cp **- we use **cp **to upload and download files.

gsutil cp 1.txt gs://[bucket-name]

image.png

Click on your bucket and check your files should be there.

image.png

Step 7 :- To list your files in your bucket.

gsutil ls gs://[bucket-name]

image.png

Step 8 :- If you want to download files from your bucket to your directory.

lets remove files from our directory.

**rm **- to remove files.

And **ls ** to list your files

image.png

gsutil cp gs://[bucket-name]/1.txt .

Now when you write this above command you will get below result.

image.png

When you do ls, you will get your files back.

image.png

Step 9 :- You can see all the ACL permissions on a given object.

**acl **- access control lists (it basically says who has the object or bucket access also the level of access like owner, admin, viewer role)

gsutil acl get gs://[bucket-name]/1.txt

image.png

Step 10 :- we are going to reader access to our object.

**ch ** - subcommands

-u - what kind of user role you want give.

gsutil acl ch -u Allusers:R  gs://[bucket-name]/1.txt

image.png

Your object will become publicly accessible after you refresh your browser.

image.png

That's it, for now, we will continue further in next blog.

Hope you liked it. Will see you on the next topic ๐Ÿ˜ƒ

##Next Topic

bvakash.hashnode.dev/google-compute-enginegce

ย