gsutil - Find Files and Folders
Asked Answered
R

2

7

Is there a find or grep-like command that I can use to search my Google Buckets?

I can only find ls, but it is not quite what I need. I want to search for specific folder names and file names, that contain a certain string or match a certain regex.

Rosiorosita answered 4/9, 2019 at 11:26 Comment(1)
The closest to a command to search is gsutil ls -r gs://[BUCKET_NAME]/[PREFIX]** wich will let you search objects by a certain prefix. Otherwise you can elaborate a script to find specific names or prefix using as example this Listing objects documentation.Shebashebang
T
12

You can use your system grep:

gsutil ls gs://[BUCKET_NAME]/** | grep {string or regexp}

No need to use -r as ** already flattens the folder structure.

Thirtieth answered 17/3, 2020 at 7:13 Comment(3)
Also useful: gsutil ls gs://[BUCKET_NAME]/**/[FILE_NAME]Larcher
@JonasBeck indeed it is - however, using simply the prefix followed by grep was significantly faster. I guess their server-side regex parsing lib is slower than grep'sCarapace
If someone else like me is using the fish command line shell, the wildcards ** don't work for this instruction. In this case use -r (or use another shell)Noncombatant
V
1

Since gsutil tool is now obsolete, here is the new command

gcloud storage ls gs://[BUCKET_NAME]/** | grep {str or regex}

note: my shell asks to escape * (star) character so for me it is

gcloud storage ls gs://[BUCKET_NAME]/\*\* | grep {str or regex}
Veronaveronese answered 13/1 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.