Skip to content

Latest commit

 

History

History
36 lines (22 loc) · 1.17 KB

glob_expanding_to_all_files_in_current_directory_recursively.md

File metadata and controls

36 lines (22 loc) · 1.17 KB

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