LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2013, 04:11 PM   #1
OMouse
LQ Newbie
 
Registered: Aug 2005
Location: Canada
Distribution: Linux Mint, Ubuntu
Posts: 13

Rep: Reputation: 7
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
 
Old 09-10-2013, 04:55 PM   #2
christine_lewis
LQ Newbie
 
Registered: Jul 2005
Location: WI
Distribution: fedora
Posts: 19

Rep: Reputation: 0
They give me the same results when I test them. What was the context where you saw the first one?
 
Old 09-10-2013, 05:41 PM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,131
Blog Entries: 2

Rep: Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833
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).
 
2 members found this post helpful.
Old 09-12-2013, 10:31 AM   #4
OMouse
LQ Newbie
 
Registered: Aug 2005
Location: Canada
Distribution: Linux Mint, Ubuntu
Posts: 13

Original Poster
Rep: Reputation: 7
Quote:
Originally Posted by christine_lewis View Post
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.
 
  


Reply

Tags
bash, globbing, wildcard


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
looking for some bash shell magic with globbing markseger Linux - Software 10 05-15-2012 09:47 AM
[SOLVED] [bash] globbing - specific filenames hashbang#! Programming 8 05-13-2011 05:00 AM
Karmic - bash globbing gone .... ??? syg00 Ubuntu 1 11-05-2009 06:25 AM
LXer: Bash Extended Globbing LXer Syndicated Linux News 0 10-09-2008 11:10 AM
Globbing Problem in BASH Hink Programming 2 07-28-2005 12:19 PM


All times are GMT -5. The time now is 11:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration