I am working on an ancient UNIX whose grep
lacks the -r/–recursive option.
I need to find an error that our application is causing, but I do not know which log file our application is writing errors to. However, I do know that the log file is somewhere in /opt
. So I want to find FooErrorMessage under /opt
in *.log
. Here's what I tried:
find /opt | xargs grep FooErrorMessage
— but this does not work, and I don't know where to specify that I just want *.log
files in the command.
Best Answer
You're just trying to find all log files under
/opt
and search them forsomethnig_I_am_looking_for
right? Why not:find /opt -name '*.log' | xargs grep something
or
find /opt | grep .log | xargs grep something
?
Oh, and since I can't figure out how to comment on the other answers: be careful with *.log as the shell will interpret that as globbing, and match all files in the current directory that end in
.log
. You should use either \*.log or '*.log'