I need to find all the instances of a given string in the whole filesystem, because I don't remember in which configuration files, script or any other programs I put it and I need to update that string with a new one.
I tried with the following command
`grep -nr 'needle' / --exclude-dir=.svn | mail [email protected] -s 'References on xxx'
If I run this command on a small directory it gives me the output I need in the form
/path1/:nn:line containing needle
/path2/:nn:line containing needle
where /path1 is the full path of the file, nn is the row containing the needle and last field is the content of the line.
However when I run the command on the root directory the grep process hang after a while. I run this script about 8 hours ago and even on a small filesystem (less than 5GB) it doesn't end and if I run top
or ps
the process seems sleeping
root 24909 0.0 0.1 3772 1520 pts/1 S+ Feb10 0:15 grep -nr needle / --exclude-dir=.svn
Why it doesn't end? Is there any better way to do this (it's a one time job, I don't need to execute this more than once)
Thanks.
Update: I found a working solution with find and xargs which seems to be working and uses less system resources than the find -exec solution. Here is my final command line:
find /{boot,etc,home,lib,lost+found,opt,root,sbin,usr,var} -type f -print0 | xargs -r0 grep -nr 'needle' | mail [email protected] -s 'References on xxx'
I used the /{dir1,dir2,...,dirn}
syntax because I want the output lines with the fullpath including the leading slash, and in this way you can use the command without cd /
i.e. from any directory.