Negative matching using grep (dopasuj linie, które nie zawierają foo)

Próbowałem wypracować składnię tego polecenia:

grep ! error_log | find /home/foo/public_html/ -mmin -60

Lub

grep '[^error_log]' | find /home/baumerf/public_html/ -mmin -60

Muszę zobaczyć wszystkie pliki, które zostały zmodyfikowane z wyjątkiem tych o nazwie error_log.

Czytałem o tym tutaj , ale znalazłem tylko jeden not-wzór regex.

 695
Author: stites, 2010-08-23

3 answers

grep -v jest twoim przyjacielem:

grep --help | grep invert  

- v, --invert-match select non-matching lines

Sprawdź także powiązane -L (dopełnienie -l).

- L, --files-without-match wyświetla tylko nazwy plików bez dopasowania

 1295
Author: Motti,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-19 22:28:50

Możesz również użyć awk do tych celów, ponieważ pozwala to na wykonywanie bardziej złożonych kontroli w jaśniejszy sposób:

Wiersze nie zawierające foo:

awk '!/foo/'

Wiersze nie zawierające ani foo, ani bar:

awk '!/foo/ && !/bar/'

Wiersze nie zawierające ani foo, ani bar, ale zawierające foo2 lub bar2:

awk '!/foo/ && !/bar/ && (/foo2/ || /bar2/)'

I tak dalej.

 80
Author: fedorqui,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-12-07 09:49:33

W Twoim przypadku prawdopodobnie nie chcesz używać grepa, ale zamiast tego dodaj negatywną klauzulę do polecenia find, np.

find /home/baumerf/public_html/ -mmin -60 -not -name error_log

Jeśli chcesz dodać symbole wieloznaczne w nazwie, musisz ich unikać, np. aby wykluczyć pliki z sufiksem .log:

find /home/baumerf/public_html/ -mmin -60 -not -name \*.log
 9
Author: Papa Smurf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-02 13:33:11