Ir al contenido principal

Google Cloud Storage: List files with wildcards

One of the most fustrating things when using Google Cloud Storage is not being able to search files using wildcards: Google Cloud web interface only allows stating a file prefix, what in many cases is not enough.

Luckly, Google Cloud SDK gsultil ls, also available throught the Google Cloud Console, allows listing storage bucket contents using wildcards. Let's see some examples:

Listing all the available buckets

gsutil ls

Listing a specific bucket content

gsutil ls gs://my_bucket

Listing, in a specific bucket, all the files matching a classic wilcard pattern

As usual, * symbol matches zero or more characters, ? symbol matches only one character.
gsutil ls gs://my_bucket/foo*.jsongsutil ls gs://my_bucket/*bar.jsongsutil ls gs://my_bucket/foo*bar.jsongsutil ls gs://my_bucket/foo*.jso?

Listing, in a specific bucket, content matching advanced wilcard pattern

A set of characters into brackets matches all the filenames that has one of those characters. For instance f[eo] would match fe and fo, but not feo.
gsutil ls gs://my_bucket/f[aeiou]o*.json

A range of characters into brackets matches all the filenames that has one of the characters in the range. For instance f[e-o] would match fe, fi and fo, but again not feio. In that way, the previous example could be written as:
gsutil ls gs://my_bucket/f[a-u]o*.json

Comentarios

Entradas populares de este blog

Linting C# in Visual Studio Code

Though very usual in programming environments as Javascript/Typescript, linting , or analyzing code for enforcing a set of coding style rules, is not usually present in the .NET based environments. Rule enforcing is really useful when working on team shared codebases in order to keep them coherent, what in last term reduces both development times and coding errors. A linting example Maybe a practical example would be helpful for explaining what  linting  is to the newcomers (feel free to go on if you aren't). Let's imagine you are a new member in a C# development team that has well established set of coding style rules. Instead (or apart) of putting them in a document, they've adopted a tool that checks these rules during the code building process. Your first code is such ambitious as this: namespace HelloWorld {      using System;      public class Program      {           p...

ESlint: Ignore unused underscore variables

Some naming conventions promote the use of the underscore character (" _ ") for those variables that must be declared but are not being used. One common case is that in which a function signature contains some variables that will not be used, as for instance the Express error handlers: app.use(function(err, req, res, next) { console.error(err.stack); res.status(500).send('Something broke!'); }); In the above example only the arguments err and res are being used, though all four must be defined in the handler signature. Thus, following the naming convention of using underscores for those unused variables, we could recode it as: app.use(function(err, _, res, __) { console.error(err.stack); res.status(500).send('Something broke!'); }); Though it makes the function more readable, it comes with a problem if using ESlint: it will blame by declaring unused variables. error '_' is defined but never used error '__' is define...

Go: Calculating the MD5 hash of a struct

In some scenarios, calculating the hash of a piece of data is useful, for instance when you only need to know that something in the dataset has changed, no matter what. Calculating a hash is moderately computing consuming but has some advantadges: Avoids checking the changes field by field of the dataset Allows storing only the data hash instead of the whole dataset In Golang, calculating MD5 hashes of structs can be achieved by using a code piece as this: import ( "bytes" "crypto/md5" "encoding/gob" "encoding/hex" "fmt" ) // Random struct, just for demo purposes type MySubStruct struct { Zaz *bool } type MyStruct struct { Foo int Bar []string Baz MySubStruct } func main() { // Hasheable struct myBool := false myStruct := MyStruct{ Foo: 67372388, Bar: []string{"b", "ar", ""}, Baz: MySubStruct{ Zaz: &myBool, }, } // Crea...