Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix wildcard selectors? (Asterisks)

Tags:

In Ryan Bates' Railscast about git, his .gitignore file contains the following line:

tmp/**/*

What is the purpose of using the double asterisks followed by an asterisk as such: **/*? Would using simply tmp/* instead of tmp/**/* not achieve the exact same result?

Googling the issue, I found an unclear IBM article about it, and I was wondering if someone could clarify the issue.

like image 909
Yuval Karmi Avatar asked Aug 20 '10 10:08

Yuval Karmi


2 Answers

It says to go into all the subdirectories below tmp, as well as just the content of tmp.

e.g. I have the following:

$ find tmp tmp tmp/a tmp/a/b tmp/a/b/file1 tmp/b tmp/b/c tmp/b/c/file2 

matched output:

$ echo tmp/* tmp/a tmp/b 

matched output:

$ echo tmp/**/* tmp/a tmp/a/b tmp/a/b/file1 tmp/b tmp/b/c tmp/b/c/file2 

It is a default feature of zsh, to get it to work in bash 4, you perform:

shopt -s globstar 
like image 78
Petesh Avatar answered Oct 11 '22 09:10

Petesh


From http://blog.privateergroup.com/2010/03/gitignore-file-for-android-development/:

(kwoods)

"The double asterisk (**) is not a git thing per say, it’s really a linux / Mac shell thing.  It would match on everything including any sub folders that had been created.  You can see the effect in the shell like so:  # ls ./tmp/* = should show you the contents of ./tmp (files and folders) # ls ./tmp/** = same as above, but it would also go into each sub-folder and show the contents there as well." 
like image 42
Hans Avatar answered Oct 11 '22 11:10

Hans