
나는 이것이 내가 끝내려고 하는 것입니다(일하는 것을 제외하고)
find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii'
내가 도대체 뭘 잘못하고있는 겁니까?
$ 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'
$
제외 목록은 결국 파일에서 나오기 때문에 grep이 필요하므로 find를 사용하여 필터링하는 것만으로는 충분하지 않습니다. grep이 NUL
종료된 목록도 반환하길 원합니다 . 그리고 나중에 이 결과를 다른 것으로 파이프할 것이므로 find 옵션이 -exec
적절한 지 모르겠습니다 .
내가 살펴본 것들:
- https://stackoverflow.com/questions/1362615/how-to-find-files- Contains-a-string-using-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
면책조항: 저는 Linux나 Shell 경험이 많지 않습니다.
답변1
파일 이름을 지정 하고 싶은 것 같습니다 grep
. 그렇게 하면 다음과 같습니다.
find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 egrep -vZ 'vvv|iii'
실제로 에서 인수로 xargs
나오는 파일 목록을 표시합니다 .find
egrep
NUL 종료 입력을 처리하기 위해 수행해야 할 작업(에서 -print0
)
find ./ -mindepth 1 -type f -mtime +60 -print0 | xargs -0 grep -EvzZ 'vvv|iii'
( egrep
더 이상 사용되지 않으므로 으로 변경했습니다 grep -E
)
에서 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.
따라서 둘 다 필요 -z
하고-Z