Search exception

I use bash after the script to search for a string in files:

find $1 -name "$2" -exec grep -Hn "$3" {} \;

Sometimes this script failed to execute

grep: /proc/sysrq-trigger: Input/Output error

To solve this problem, I first decided to exclude this file from the search result. it is a good idea, and if so, how can I do this? Is there any other solution to avoid my script failure?

+3
source share
2 answers

You can exclude the entire directory /procto find the following:

find $1 -path /proc -prune -o -name "$2" -print -exec grep -Hn "$3" {} \;
+4
source

, , , --exclude-dir , grep it self (grep -r), grep find. xargs proc grep?

find $1 -name "$2" | grep -v '/proc' | xargs grep -Hn "$3" {} \;
+2

All Articles