I know **/*.ext
expands to all files in all subdirectories matching *.ext
, but what is a similar expansion that includes all such files in the current directory as well?
views:
145answers:
4
+1
A:
$ find . -type f
That will list all of the files in the current directory. You can then do some other command on the output using -exec
$find . -type f -exec grep "foo" {} \;
That will grep each file from the find for the string "foo".
Amir Afghani
2009-11-06 22:10:47
+1
A:
This wil print all files in the current directory and its subdirectories which end in '.ext'.
find . -name '*.ext' -print
unutbu
2009-11-06 22:11:25
+1
A:
This will work:
ls -l {,**/}*.ext
In order for the double-asterisk glob to work, the globstar
option needs to be set (default: on):
shopt -s globstar
From man bash
:
globstar If set, the pattern ** used in a filename expansion con‐ text will match a files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match.
Dennis Williamson
2009-11-06 23:22:49