我在file.lst
中有一个文件列表。
现在,我想查找目录dir
中超过7天的所有文件,但file.lst
文件中的文件除外。如何修改查找命令或从结果中删除file.lst
中的所有条目?
示例:
file.lst
:
a
b
c
执行:
find -mtime +7 -print > found.lst
found.lst
:
a
d
e
所以我期待的是:
d
e
答案 0 :(得分:26)
通过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.
答案 1 :(得分:3)
使用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