查找不在列表中的文件

时间:2011-09-05 10:50:14

标签: linux bash command-line find diff

我在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

2 个答案:

答案 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