LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash/ls globbing patterns, wildcards (https://www.linuxquestions.org/questions/linux-newbie-8/bash-ls-globbing-patterns-wildcards-4175476648/)

OMouse 09-10-2013 04:11 PM

Bash/ls globbing patterns, wildcards
 
I've encountered a few different glob patterns and I'm not sure exactly what they do:

app/js/**/*.js

Is that the same as this?

app/js/*/*.js

christine_lewis 09-10-2013 04:55 PM

They give me the same results when I test them. What was the context where you saw the first one?

TobiSGD 09-10-2013 05:41 PM

Using ** instead of * means that you want to have recursive globbing from that directory level on.

For example
Code:

tobi ~/test ☺ $ tree
.
├── a
├── b
│** ├── c
│** │** └── d
│** │**    └── y.txt
│** └── y.txt
├── c
│** └── y.txt
├── d
└── e

7 directories, 3 files
tobi ~/test ☺ $ echo */y.txt
b/y.txt c/y.txt
tobi ~/test ☺ $ echo **/y.txt
b/c/d/y.txt b/y.txt c/y.txt

As you can see, the ** version will find all files y.txt in the tree, the version with the single asterisk will work the usual way.
This makes it easier to launch commands on files in unknown places without having to use the find command, but it is limited by the maximum length of the commandline your shell allows (which is usually pretty high).

OMouse 09-12-2013 10:31 AM

Quote:

Originally Posted by christine_lewis (Post 5025499)
They give me the same results when I test them. What was the context where you saw the first one?

it was in the context of a JavaScript Test runner which was searching for test files to run within sub-directories. My issue was that both */*.js and **/*.js were returning the same results, maybe because my directory hierarchy was fairly flat.


All times are GMT -5. The time now is 05:10 PM.