Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

77%
+5 −0
Q&A Documentation for double asterisk glob expansion

While * belongs to the POSIX standard, ** is an extension. You are right it's not in man 7 glob. Tools that treat ** specially (i.e. not as * simply followed by *) tend to agree what it means, but ...

posted 9mo ago by Kamil Maciorowski‭

Answer
#1: Initial revision by user avatar Kamil Maciorowski‭ · 2023-09-06T04:35:53Z (9 months ago)
While [`*` belongs to the POSIX standard][1], `**` is an extension. You are right it's not in `man 7 glob`. Tools that treat `**` specially (i.e. not as `*` simply followed by `*`) tend to agree what it means, but AFAIK it's only because there is a consensus, not because they all use some common library (like `glob()` [mandated by POSIX][5]) whose documentation could be the ultimate answer to your question.

I'm afraid the best you can get is the documentation of each tool, separately. The links you posted are exactly this.

None of your links covers `ls **/*` though. This example works because the shell expands `**/*` before `ls` is even started. You tagged `bash`, therefore I assume your shell is Bash. For Bash these are the relevant fragments of the documentation:

> `*`  
Matches any string, including the null string. When the `globstar` shell option is enabled, and `*` is used in a filename expansion context, two adjacent `*`s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a `/`, two adjacent `*`s will match only directories and subdirectories.

<sup>([source][2])</sup>

>`globstar`  
If set, the pattern `**` used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a `/`, only directories and subdirectories match.

<sup>([source][3])</sup>

Any other shell (or whatever tool) that supports `**` shall document it for itself.

Notes:

- Because `**` is an extension, some tools by default suppress their support unless you explicitly enable it. E.g. [here][4] (it's one of the links you posted) we can read "If `recursive` is true,  the pattern `**` will …"; but by default `recursive=False`. Similarly in Bash `**` is by default just `*` followed by `*`, this changes when you invoke `shopt -s globstar`.
- There is no guarantee all tools that treat `**` specially will expand it in *exactly* the same way. In general there may be edge cases and nuances. Always refer to the documentation of the tool you're actually using.

  [1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
  [2]: https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
  [3]: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
  [4]: https://docs.python.org/3/library/glob.html
  [5]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/glob.html