LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question about a Linux command line tool (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-a-linux-command-line-tool-917939/)

silentray 12-09-2011 12:57 PM

Question about a Linux command line tool
 
Hi

I used to see one of my colleagues uses a very cool command line tool which uses ** to represent any number of folder hierarchy.

For example:
If there is a file MyFile.java somewhere in:
~/devel/project/component/src/server/com/mycompany/MyFile.java

The tool can simply list the file by using:
ls -l **/MyFile.java

Can anyone let me know what this tool is?

Many thanks
Kevin

SecretCode 12-09-2011 01:05 PM

I am not familiar with a tool that uses ** like that - but find would get the job done
Code:

find ~ -name MyFile.java -ls

MTK358 12-09-2011 01:50 PM

It's bash's "globstar" option:

Code:

shopt -s globstar

SecretCode 12-09-2011 02:25 PM

There's something worth learning

Although I see that like * it only matches non-hidden directories, so ls -l **/session.rdf won't find session.rdf in .mozilla/ (nor will ls -la **/session.rdf).

David the H. 12-10-2011 12:09 PM

Use shopt -s dotglob to force globs to match hidden files.

Also, whatever globbing pattern follows **/ will be applied to the top-level directory as well as all subdirectories. So you can use **/.[^.]* to list all dotfiles in the tree (with [^.] there to keep it from matching the . and .. directories).


All times are GMT -5. The time now is 03:00 PM.