Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to run this command.

grep -rin "wp_get_attachment_url" *

But the underscores (_) in the string value seems to mess up the grep command. How do I search the string values that have underscores?

share|improve this question
Can you explain "mess up the grep command"? It works fine here in Ubuntu 11.10. – htorque Nov 1 '11 at 21:10
up vote 1 down vote accepted

If wp_get_attachment_url is actually an URL that must be interpreted literally, use single quotes to prevent the shell from interpreting characters. Furthermore, use the -F option of grep to avoid it from interpreting the pattern as a regular expression. interpreted as a regular expression would match either http://example.comid=1 or, but not

The command becomes:

grep -rinF '' *

If the pattern contains a ', use '\'' to escape it:

grep -rinF 'mornin'\'' all' *

A hint: * matches all non-hidden files in the current directory. If you want to match dot-files as well, just grep the current directory recursively (-r):

grep -rinF 'search term' .
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.