Results 1 to 8 of 8
Hello all,
I am interested in a more flexible targeted search in my directories. For example, if I am searching for all .txt .dat and .bat files (then perform an ...
- 06-02-2011 #1Just Joined!
- Join Date
- Jun 2011
- Posts
- 4
using brace expansion with find
Hello all,
I am interested in a more flexible targeted search in my directories. For example, if I am searching for all .txt .dat and .bat files (then perform an operation), I would think that the following would work:
find . -name '*.{txt,dat,bat}' -exec ...
But I get no results. I am running on Cygwin.
I have confirmed that:
find . -name '*.txt' -exec ...
find . -name '*.dat' -exec ...
find . -name '*.bat' -exec ...
all find the aforementioned files. But,
find . -name '*.{txt}'
still produces no output.
Thanks for any assistance
- 06-02-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
how bout:
Code:find . -name '*.txt' -o -name '*.dat' -o -name '*.bat' -exec ...
- 06-02-2011 #3Just Joined!
- Join Date
- Jun 2011
- Posts
- 4
ateryu,
Thanks for the suggestion. This will work.
Though, I am still curious as to how to incorporate the brace expansion into the find statement. This will significantly simplify things as lists of file types get larger.
Adam
- 06-02-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
okay, how bout this? it which just 'ls' every file that it finds:
the curly braces are just a variable substitution for each file found, and the backslash semicolon is required to tell find you are done with the variable.Code:find . -name '*.txt' -o -name '*.dat' -o -name '*.bat' -exec ls -l {} \;
- 06-03-2011 #5Just Joined!
- Join Date
- Jun 2011
- Posts
- 4
This is basically what I have been doing:
find . -name '*.txt' -exec grep -l 'Find this' {} \;
I would like to know if there is a more elegant way to use brace expansion instead of typing out each :
-o -name '*.txt'
BTW how do you get your example in 'code' format? I am new to this message board.
Thanks.
- 06-03-2011 #6Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
sorry, but i'm not sure what you mean by more elegant. you could just do this in straight grep though, e.g.:
you can make your text appear as code by highlighting your text, then clicking the '#' character in the above formatting bar.Code:grep -l 'Find this' *.txt
- 06-03-2011 #7Just Joined!
- Join Date
- Jun 2011
- Posts
- 4
When I am refering to more elegant, I would like to not have to use multiple -o -name in my find command. To be able to use the brace expansion:
to search for all such files in the subfolders. It is not the grep part that I am concerned with right now. Just getting the aforementioned expansion to work with 'find'.Code:*.{dat,txt,bat,cv,irh}
BTW, thanks for the help with the code highlight. I needed to open the 'advanced features' button to access that capability.
Thanks,
- 06-05-2011 #8Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
I don't know of another way to pass multiple searches to find, sorry.


Reply With Quote