How to grep a string from all the files under /
I am looking for files which contains a string for example "my text". But I don't know where the file locates. So I look for all the files do as follow (seems crazy):
Code:
grep -r "my text" * Is this command wrong? |
Quote:
Code:
path="/path/of/interest" |
This should work all recent versions of bash.
Code:
grep -R "my text" * |
Quote:
|
Quote:
Code:
find /path/of/interest -type f -exec grep "my string" "{}" + |
Quote:
|
Quote:
The problem by your solution is, one has to know the path. |
Quote:
Quote:
|
If the above methods were too complicated and/or didn't produce the results you want, you may not find this any better, but try:
Code:
for files in $(find / -name "*" -type f); do Sasha |
Quote:
Code:
grep -lir "your text" / |
Obvious newbie question(or answer?)... Why couldn't you just use
ls / | grep -switch "string" ? |
Quote:
Code:
/root |
Quote:
|
Quote:
Quote:
|
Quote:
EDIT: And, as pwc101 hinted at above, ls can produce results that the next-in-pipe command has troubles with, producing weird errors. Cheers :) Sasha |
All times are GMT -5. The time now is 03:48 PM. |