How can I use find
to find all files that have a .xls
or .csv
extension? I have seen a -regex
option but I don't know how to use it.
2 Answers
Why not simply use this:
find -name "*.xls" -o -name "*.csv"
You don't need regex for this.
If you absolutely want to use regex simply use
find -regex ".*\.\(xls\|csv\)"
-
9
-
1Why is a backslash needed before the parenthesis? I know it doesn't work without it, but it seems like it should.– MCSDec 9, 2008 at 16:05
-
1because they are emacs regular expressions by default. use -regextype to change that.– user601Dec 9, 2008 at 16:15
-
4Just for the record: I can never remeber which tools want "\(" for grouping and which want "(". I always have to try it to know it. Dec 9, 2008 at 16:49
-
2
find . \( -name \*.xls -o -name \*.csv \) -print
-
Didn't know about the -o option. Thanks!– MCSDec 9, 2008 at 16:02
-
1Does it need parentheses? find . '(' -name *.xls -o -name *.csv ')'-print– Adrian PronkDec 9, 2008 at 21:48
-
@Adrian - no, it doesn't. I'm not sure if it would need parens on a non-GNU find where "-print" wasn't already the default action. Dec 10, 2008 at 13:09
-
5Well, GNU find ( default on ubuntu 11.04) works correctly with both parens and -print OR without (parens and -print). But
find . -name \*.xls -o -name \*.csv -print
outputs only files matching .csv,– bbaja42Jan 2, 2012 at 14:20 -