-1

I hava a Google Cloud Storage instance and need to get a txt file with the metadata from my files

I have two paths in my GCS enviroment, i need to list the metadata from the files in each path and copy it to a local txt file, i can list all the metadata but can't copy to local file, i've used the code below to list the metadata and it works, but i don't know how to copy this.

gsutil ls -L gs://my_bucket/images/**

it lists all my metadata i just want this information on a local txt file

2 Answers2

2

If you are going to use the command that I shared be aware that you can not write directly to a bucket, so I recommend you choose another folder like home for example, for work with buckets from console there are specialized gsutil commands[1], neverthless, you can use a script to store the .txt file in the bucket.

#!/bin/bash
gsutil ls -L gs://my_bucket/directory/** > /home/directory/metadata.txt 
gsutil cp /home/directory/metadata.txt gs://mybucket 

you can save this lines in a .sh file:

/home/script.sh

and later execute the script:

sh script.sh

this allow to you to save metadata on the bucket in a .txt file

[1] https://cloud.google.com/storage/docs/gsutil/commands/cp

Harif Velarde
  • 733
  • 5
  • 10
1

You can try to use this command on Cloud shell:

gsutil ls -L gs://my_bucket/folder/** > /home/other_folder/metadata.txt

This command allows to you write the outcome of gsutil and write a file where you need.

To download the file you can use download file option from Cloud shell and get metadata information you need.

HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44
Harif Velarde
  • 733
  • 5
  • 10
  • Hello! I've created a new folder inside my bucket and uploaded an empty metadata.txt file. tried to use "gsutil ls -L gs://my_bucket/images/** > gs://my_bucket/Metadata/metadata.txt" but it says that the directory or the file doesn't exists. – Iago Losada Alibune Jun 26 '19 at 17:09
  • Hello, I left another answer in the post – Harif Velarde Jun 28 '19 at 00:29