How Do I Use Grep Command to Find a Text That Includes a String Like /Usr/Vm/Data/?

I want to use grep command to search for files containing the string "/usr/vm/data". For searching a normal string like "how are you", i know i can do:

grep -inr "how are you" *

to search recursively. But i am getting stuck in the cases where i need to search a path like "/usr/vm/data". I tried: grep -inr "\/usr\/vm\/data" directory1

and also grep -inr "/usr/vm/data/" directory1 but didn't get any success.

2 Answers

Don't torture yourself, and it is a normal string (especially when you put it in quotes).

echo "/usr/vm/data Hello world" | grep -i "/usr/vm/data"
0

Your command works fine:

$ cat directory1/somefile
foo
bar
this line contains /usr/vm/data/
$ grep -inr "/usr/vm/data/" directory1
directory1/somefile:3:this line contains /usr/vm/data/
$

Perhaps your file is beyond a symlink which grep doesn't follow, or perhaps you don't have any matching files?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest