Linux – How to search the entire system (Linux) for a particular string

bashlinux

I need to find this string:

7z a -p

I've tried:

grep -iR "7z a -p" /

But it seems to hang after a while, with lots of:

grep: /sys/class/vc/vcs5/power/autosuspend_delay_ms: Input/output error
grep: warning: /sys/class/vc/vcsa5/subsystem: recursive directory loop
grep: /sys/class/vc/vcsa5/power/autosuspend_delay_ms: Input/output error
grep: warning: /sys/class/vc/vcs6/subsystem: recursive directory loop

EDIT – However, this seems to just look at static text files. In addition, what about runtime areas, memory and processes? ie the entire system? eg for mysql:

ps aux | grep "mysql -u user -p"

shows :

38164  4292 pts/0    S+   13:16   0:00 mysql -uodbcuser -px xxxxxxxx

Interestingly ps aux does hide the password with xxxxx. I can try with 7zip but it's quite fast, it has to be running at the same time as you run the ps aux command to "catch it.

Best Answer

You should exclude directories like /sys/, /proc/ and /dev/ from your command:

grep -iR --exclude-dir='/sys' --exclude-dir='/proc' --exclude-dir='/dev' "7z a -p" /