Match all files under all nested directories with shell globbing

Samer Buna picture Samer Buna · Dec 3, 2010 · Viewed 10.5k times · Source

Is there a way to use shell globbing to identify nested directories?

so if I have dir/dir1/dir2/dir3/dir4/dir5/.. and I have files under all of them, what is the equivalent globbing pattern to match all files under all directories, similar to - for example - ls -R

Answer

Dennis Williamson picture Dennis Williamson · Dec 3, 2010

In Bash 4, with shopt -s globstar, and zsh you can use **/* which will include everything except hidden files. You can do shopt -s dotglob in Bash 4 or setopt dotglob in zsh to cause hidden files to be included.

In ksh, set -o globstar enables it. I don't think there's a way to include dot files implicitly, but I think **/{.[^.],}* works.