繁体   English   中英

查找不在列表中的文件

[英]find files not in a list

我在file.lst中有一个文件列表。 现在我想查找目录dir中超过 7 天的所有文件,除了file.lst文件中的文件。 如何修改 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-command 传递给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
a  b  c  d  file.lst

$ cat file.lst 
a$
b$
c$


$ find . | grep -vf file.lst 
.
./file.lst
./d

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM