'How does the ** work while searching for a Path
I didn't find a lot of info about this, as far as I know it matches filenames and directories recursively, but how does it work?
Solution 1:[1]
The glob-expression ** is used to match all files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match.
This means that it is used in a recursive file-search during path-name expansion patterns on the command line.
Depending on the shell you use, it needs to be enabled. In bash this is done with:
$ shopt -s globstar
Here are examples:
# list all files recursively
$ echo **
# list all files recursively that end with .txt
$ echo **/*.txt
# list all files recursively that are in a subdirectory foo
$ echo **/foo/**
Beware that the following pattern does not work recursively **.txt. This is just seen as a combination of two single asterisk globs and is identical to *.txt.
Note: there are subtle differences between bash and zsh, but in general it works the same.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
