How to grep on the whole server in UNIX command

Dear friends,

I need to use the grep command on the whole Unix server. What I mean I need to search for ‘String’ in / file system. I try

grep -r 'string' / 

Not working. Can you suggest work around?

That should work. Another option is combination of find and grep:

sudo find / -type f -exec grep "String-To-Search-here" {} \;

OR

sudo find / -type f -print0 | xargs -0 -I {} grep -l 'Words-To-Search-Here' "{}"

Where find command options are:

  • -type f : Only search for files. For dirs, try -type d
  • -print 0 : Deal with special file names.

xargs options are:

  • -0 : Deal with input files sent by find that might contain white space, quote marks, or backslashes
  • -I {} : Replace occurrences of {} in the initial-arguments with names read from standard input i.e. file name pass to the grep command. See grep command examples:

https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/