views:

145

answers:

4

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?

+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
+1  A: 

This wil print all files in the current directory and its subdirectories which end in '.ext'.

find . -name '*.ext' -print
unutbu
+1  A: 

Using find should do it for you:

find . -type f -name \*.ext
Carl Norum
+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