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
The Bash shell feature that is used for matching or expanding specific types of patterns is called globbing. Globbing is mainly used to match filenames or searching for content in a file. Globbing uses wildcard characters to create the pattern.
p>File globbing also known as Path Name Expansion. It is the method of recognizing wildcard patterns in linux and then finding the file path expansion based on these patterns. Wildcard Patterns are strings that are used for selection of multiple files based on patterns.
Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines. Using the grep command, we can recursively search all files for a string on a Linux.
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.
Specifically about git (gitignore, gitattributes, and commands that take filenames): if the pattern contains no slash, *
wildcards will match deep. If it does contain a slash, git will call fnmatch with the FNM_PATHNAME
flag, and simple wildcards won't match slashes. **
to match deep isn't supported. Maybe this kind of deep matching could be more widely supported with a new FNM_STARSTAR
flag, and an implementation in glibc, gnulib and other places.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With