Находить файлы не в списке
У меня есть список файлов в file.lst
.
Теперь я хочу найти все файлы в каталоге dir
, которые старше 7 дней, кроме тех, что находятся в файле file.lst
. Как я могу либо изменить команду find, либо удалить все записи в file.lst
из результата?
Пример:
file.lst
:
a
b
c
Execute:
find -mtime +7 -print > found.lst
found.lst
:
a
d
e
так что я ожидаю:
d
e
Ответы
Ответ 1
Произведите команду find
через grep -Fxvf
:
find -mtime +7 -print | grep -Fxvf file.lst
Что означают флаги:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.
-x, --line-regexp
Select only those matches that exactly match the whole line.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.
Ответ 2
Настройте команду find на grep
с помощью переключателей -v
и -f
find -mtime +7 -print | grep -vf file.lst > found.lst
Параметры grep:
-v : invert the match
-f file: - obtains patterns from FILE, one per line
Пример:
$ ls
a b c d file.lst
$ cat file.lst
a$
b$
c$
$ find . | grep -vf file.lst
.
./file.lst
./d