Skip to content

Instantly share code, notes, and snippets.

@fonylew
Created September 4, 2021 06:01
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save fonylew/3ada58ed64b78c5e886d5f5d96a15487 to your computer and use it in GitHub Desktop.
Save fonylew/3ada58ed64b78c5e886d5f5d96a15487 to your computer and use it in GitHub Desktop.
# สร้าง bucket
gsutil mb gs://[BUCKET]
# ลิสต์ files ใน bucket
gsutil ls gs://[BUCKET]
# ดูว่า bucket ขนาดเท่าไร (du: disk usage)
gsutil du -sh gs://[BUCKET]
# Copy (upload) ไฟล์ไปยัง bucket
gsutil cp [File] gs://[BUCKET]
# > การ upload ไม่จำเป็นต้องสร้าง directory ล่วงหน้า
gsutil cp [File] gs://[BUCKET]/path/to/file
# > การ copy (upload) ทั้ง directory (-r)
gsutil cp -r [Folder] gs://[BUCKET]
# > การใช้ enable multiprocessing (-m) ช่วยให้ copy ไฟล์ได้เร็วขึ้น
gsutil -m cp -r [Folder] gs://[BUCKET]
# > การ copy (download) ไฟล์จาก bucket
gsutil cp gs://[BUCKET]/path/to/file [File]
# > การ copy (download) directory มายัง current directory
gsutil -m cp -r gs://[BUCKET]/path .
# > copy (download) เฉพาะไฟล์ txt มายัง current directory
gsutil -m cp gs://[BUCKET]/*.txt .
# Move หรือ rename ไฟล์
gsutil mv gs://[BUCKET]/path/to/old_name gs://[BUCKET]/path/to/new_name
# Remove ลบไฟล์ file หรือ directory
# > remove การลบไฟล์
gsutil rm gs://[BUCKET]/path/to/file
# > remove การลบ directory
gsutil rm -r gs://[BUCKET]/path/to/directory
# Doc: https://cloud.google.com/storage/docs/how-to