0

I need to recursively search my filesystem using a 'grep' or 'find' command to match any filename that contains the string "report".

I attempted the command

find | grep "report[[:alnum:]]\."

and while this was close to the output I wanted, it only gave files that END in 'report.(php/tpl/whatever)'

What is wrong with this command, or what can I use to produce the desired output?

Dtown
  • 37
  • 1
  • 7
  • 3
    `find . -name "*report*"` ?? – fedorqui Jun 12 '14 at 15:55
  • Perfect mate, thank you. Exactly what I wanted. Any reason behind the syntax using quotes and asterisks in "* report *" ? – Dtown Jun 12 '14 at 16:08
  • `*` matches anything (even the empty string). Hence, this expression matches all names being like `XXXXreportYYYY`. The usage of quotes is to avoid bash expansion. – fedorqui Jun 12 '14 at 16:10
  • 1
    Great, thanks again. Add this as an answer so I can select it as correct. – Dtown Jun 12 '14 at 16:14
  • @taylordustin This may be biased, but there are still characters that expand in double quotes, i.e. `$`, `!`, etc... So if you're unsure about expansion rules, I would suggest using single quotes when you want bash to treat something as a literal string (in this case you want `find` to process the special characters and `bash` to treat it as a string). – Reinstate Monica Please Jun 15 '14 at 01:06

1 Answers1

1

You can use the following find command:

find . -name "*report*"

* matches anything (even the empty string). Hence, this expression matches all names being like XXXXreportYYYY.

The usage of quotes is to avoid bash expansion (try echo * and see what happens! - How do I escape the wildcard/asterisk character in bash? may help).

Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598