1

I tried the below command to search for in all files user /var

sudo find . -type f | xargs sudo grep 202007602 | tee /tmp/202007602.log

Output:

grep: ./www/html/jenkins/workspace/node_modules/xpath/docs/xpath: No such file or directory
grep: methods.md: No such file or directory
grep: ./www/html/jenkins/workspace/Efendibey-Live/node_modules/xpath/docs/function: No such file or directory
grep: resolvers.md: No such file or directory
sudo: unable to execute /bin/grep: Argument list too long
sudo: unable to execute /bin/grep: Argument list too long

Then, I tried a solution from stackoverflow but that too does not work and i get the below error:

sudo find /var -type f -exec sudo grep -l '202007602' {} + | tee /tmp/202007602.log
sudo: unable to execute /bin/grep: Argument list too long
sudo: unable to execute /bin/grep: Argument list too long
....
....

I'm using centos 7.

Can you please suggest ?

2
  • 1
    Why do you use sudo both on the find and on the grep? It should be enough to have find run with sudo. Drop the sudo from -exec sudo grep. Does that solve it?
    – Kusalananda
    Sep 13, 2020 at 6:14
  • In your first attempt, filenames are obviously being split. You need to use -print0 in find, and -0 in xargs, to fix this. In your second attempt, -exec requires a ";" to terminate the enclosed command. Sep 13, 2020 at 10:07

1 Answer 1

0

Let GNU grep do the work for you with its -r flag

sudo grep -r 202007602 /var | tee /tmp/202007602.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.