我有一个file.lst
文件的列表。 现在,我想查找目录dir
所有文件,除了file.lst
文件中的文件之外,它们都是7天以前的文件。 如何修改find命令或从结果中删除file.lst
中的所有条目?
例:
file.lst
:
a b c
执行:
find -mtime +7 -print > found.lst
found.lst
:
a d e
所以我期望的是:
d e
通过grep -Fxvf
管道find
命令:
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.
使用-v
和-f
开关将find命令传递给grep
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 abcd file.lst $ cat file.lst a$ b$ c$ $ find . | grep -vf file.lst . ./file.lst ./d