0

We can run a gsutils command to delete objects as follows:

gsutil rm -a gs://bucket/**

Now I would like to only remove certain folders following a wildcard pattern:

gs://bucket/folder/{WILDCARD-A}/folderA/{WILDCARD-B}/folderB

The idea is to delete all files with target folder B.

How can this be achieved with gsutils?

6
  • 1
    Have you tried gsutil rm -r gs://bucket/folder/{WILDCARD-A}/folderA/{WILDCARD-B}/folderB applying your wildcat patterns? If you want to bulk delete a hundred thousand or more objects, avoid using gsutil, as the process takes a long time to complete. Commented May 24, 2022 at 21:28
  • What is the alternative to remove objects? Commented May 24, 2022 at 21:29
  • @JohnAndrews Based on the context of your original question, that specific inquiry will require a new posted question as per Stack Overflow rules. Commented May 24, 2022 at 22:55
  • 1
    (@OsvaldoLópez: wildcat?) Commented Jun 8, 2022 at 10:33
  • I’m voting to close this question because it's not a programming question - please read the tag wiki of google-cloud-storage Commented Jun 10, 2022 at 3:27

1 Answer 1

2

Try gsutil rm -r gs://bucket/folder/{WILDCARD-A}/folderA/{WILDCARD-B}/folderB applying your wildcard patterns. If you have a large number of objects to remove, use the gsutil -m option, which enables multi-threading/multi-processing. In case you need to bulk delete a hundred thousand or more objects, avoid using gsutil, as the process takes a long time to complete. Instead use the Google Cloud console, which can delete up to several million objects, or Object Lifecycle Management, which can delete any number of objects.

Sign up to request clarification or add additional context in comments.

2 Comments

Was this answer useful?
This solved it. Basically I put * for every place in the pattern where a wildcard was needed. There are some notes on the performance, as also outlined in the link you provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.