I know that there is an operator similar to the *, with the difference that it works into all the sub-directories.
Assume you have a folder structure:
.
├── bar
│ ├── foo
│ │ └── baz
│ │ └── hurz
│ │ └── lolz
│ │ └── hello.txt
│ └── poit.txt
└── fnord.txtThen ls with single star * would list:
$ ls *.txt
fnord.txtI expect the double star operator ** to work on the subfolders, yet it is not complete. I know that this can work as I had this enabled on another machine yet I forgot how.
$ ls **/*.txt
bar/poit.txtI was expecting the output to look like:
ls **/*.txt
bar/foo/baz/hurz/lolz/hello.txt bar/poit.txt fnord.txtHow is the ** operator called and how do I activate it properly?
1 Answer
You are looking for the globstar shell option which was introduced in bash version 4.
If you unsure what version you are running you can test that via:
$ echo $BASH_VERSION
4.4.12(1)-releaseCheck if it is enabled via:
$ shopt globstarIt defaults to off. If you want to use it you have to enable it:
$ shopt -s globstarThen it will work as expected. You might want to add this to your .bashrc for it to be always enabled in new shells.
To disable it:
$ shopt -u globstarSee help shopt for details.