72

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 Answers2

124

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\)"
14
find . \( -name  \*.xls -o -name \*.csv \) -print
Paul Tomblin
  • 1,678
  • Didn't know about the -o option. Thanks! –  Dec 09 '08 at 16:02
  • 1
    Does it need parentheses? find . '(' -name *.xls -o -name *.csv ')'-print –  Dec 09 '08 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. – Paul Tomblin Dec 10 '08 at 13:09
  • 5
    Well, 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, – bbaja42 Jan 02 '12 at 14:20
  • You're right, I need the parens. – Paul Tomblin Jan 02 '12 at 15:02
  • +1 for grouping them; very useful if you want to use some more options. – l0b0 Mar 19 '13 at 16:16