Negative matching using grep (match lines that do not contain foo)
I have been trying to work out the syntax for this command:
grep ! error_log | find /home/foo/public_html/ -mmin -60
or
grep '[^error_log]' | find /home/baumerf/public_html/ -mmin -60
I need to see all files that have been modified except for those named error_log .
I've read about it here, but only found one not -regex pattern.
grep -v is your friend:
grep --help | grep invert
-v, --invert-match select non-matching lines
Also check out the related -L (the complement of -l ).
-L, --files-without-match only print FILE names containing no match
You can also use awk for these purposes, since it allows you to perform more complex checks in a clearer way:
Lines not containing foo :
awk '!/foo/'
Lines not containing neither foo nor bar :
awk '!/foo/ && !/bar/'
Lines not containing neither foo nor bar but containing either foo2 or bar2 :
awk '!/foo/ && !/bar/ && (/foo2/ || /bar2/)'
And so on.
In your case, you presumably don't want to use grep, but add instead a negative clause to the find command, eg
find /home/baumerf/public_html/ -mmin -60 -not -name error_log
If you want to include wildcards in the name, you'll have to escape them, eg to exclude files with suffix .log:
find /home/baumerf/public_html/ -mmin -60 -not -name *.log
链接地址: http://www.djcxy.com/p/12886.html
上一篇: Linux查找和grep命令一起
