
Das ist es, was ich erreichen möchte (außer zu arbeiten)
find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii'
Was mache ich falsch?
$ ll
total 0
-rw-rw-r-- 1 yyy yyy 0 Sep 18 10:36 iii.txt
-rw-rw-r-- 1 yyy yyy 0 Aug 29 10:35 old1.txt
-rw-rw-r-- 1 yyy yyy 0 Aug 29 10:35 old2.txt
-rw-rw-r-- 1 yyy yyy 0 Aug 29 10:35 old3.txt
-rw-rw-r-- 1 yyy yyy 0 Nov 16 09:36 vvv.txt
-rw-rw-r-- 1 yyy yyy 0 Nov 5 09:41 young.txt
$ find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -viZ 'vvv|iii'
$ find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vilZ 'vvv|iii'
$ find ./ -mindepth 1 -type f -mtime +60 -print0
./old3.txt./old1.txt./old2.txt$ find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep 'old'
$ find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 grep 'old'
$ find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 grep 'o'
$ find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 grep '.*o.*'
$ find ./ -mindepth 1 -type f -mtime +60 | xargs egrep 'o'
$ find ./ -mindepth 1 -type f -mtime +60 | xargs egrep '.*o.*'
$ find ./ -mindepth 1 -type f -mtime +60
./old3.txt
./old1.txt
./old2.txt
$ find ./ -mindepth 1 -type f -mtime +60 | grep 'o'
./old3.txt
./old1.txt
./old2.txt
$ find ./ -mindepth 1 -type f -mtime +60 | xargs grep 'o'
$ find ./ -mindepth 1 -type f -mtime +60 -print | xargs grep 'o'
$ find . -name "*.txt" | xargs grep "old"
$ find . -name "*.txt"
./old3.txt
./vvv.txt
./iii.txt
./old1.txt
./old2.txt
./young.txt
$ find ./ | grep 'o'
./old3.txt
./old1.txt
./old2.txt
./young.txt
$ find ./ | xargs grep 'o'
$
Ich brauche das Grep, weil die Ausschlussliste am Ende aus einer Datei kommt, also reicht es nicht ganz aus, einfach „Find“ zum Filtern zu verwenden. Ich möchte, dass das Grep NUL
auch eine beendete Liste zurückgibt. Und ich werde das Ergebnis danach an etwas anderes weiterleiten, also weiß ich nicht, ob die Option „Find“ -exec
angemessen wäre.
Dinge, die ich mir angesehen habe:
- https://stackoverflow.com/questions/1362615/wie-finde-ich-dateien-die-einen-string-enthalten-mit-egrep
- http://www.unixmantra.com/2013/12/xargs-all-in-one-tutorial-guide.html
$ bash -version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
$ cat /proc/version
Linux version 2.6.18-371.8.1.0.1.el5 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)) #1 SMP Thu Apr 24 13:43:12 PDT 2014
Haftungsausschluss: Ich habe nicht viel Erfahrung mit Linux oder Shells.
Antwort1
Es sieht so aus, als ob Sie dies auf Dateinamen anwenden möchten grep
. Wenn ja, gilt Folgendes:
find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii'
stellt tatsächlich die Liste der Dateien dar, die als Argument für xargs
herauskommen .find
egrep
Was Sie tun sollten, um mit NUL terminierte Eingaben zu verarbeiten (von -print0
)
find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 grep -EvzZ 'vvv|iii'
( egrep
ist veraltet, deshalb habe ich es geändert in grep -E
)
Aus man grep
:
-z, --null-data
Treat the input as a set of lines, each terminated by a zero
byte (the ASCII NUL character) instead of a newline. Like the
-Z or --null option, this option can be used with commands like
sort -z to process arbitrary file names.
-Z, --null
Output a zero byte (the ASCII NUL character) instead of the
character that normally follows a file name.
Sie brauchen also beides -z
und-Z