til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Glob expanding to all files in current directory recursively

Oftentimes you want to process all files in a deep filestructure recursively.

In bash this can be accomplished with the following glob: {,**/}*.ext

To see it in action, try with ls

$ ls -1 {,**/}*.*
example/ignoreme.txt
test.t

I picked this up from a marvellous response on StackOverflow.

If you like me attempt to do secure shell scripting, do note that this does not work with: set -f

Disable filename expansion (globbing) upon seeing *, ?, etc.

This took me some time to figure out.

I use the globbing trick when processing a deep structure of XML files using xmllint:

$ xmllint --noout --schema my.xsd xml/{,**/}*.xml

Another explanation is available here from unix.stackexchange.com.

Resources and References

  1. StackOverflow: “What expands to all files in current directory recursively?”
  2. TIL: “Write Safe Shell Scripts