查找不在列表中的文件

时间:2022-08-30 00:15:33

I have a list of files in file.lst. Now I want to find all files in a directory dir which are older than 7 days, except those in the file.lst file. How can I either modify the find command or remove all entries in file.lst from the result?

我在file.lst中有一个文件列表。现在我想查找目录dir中超过7天的所有文件,但file.lst文件中的文件除外。如何修改find​​命令或从结果中删除file.lst中的所有条目?

Example:

例:

file.lst:

file.lst:

a
b
c

Execute:

执行:

find -mtime +7 -print > found.lst

found.lst:

found.lst:

a
d
e

so what I expect is:

所以我期望的是:

d
e

2 个解决方案

#1


22  

Pipe your find command through grep -Fxvf:

通过grep -Fxvf管道你的find命令:

find -mtime +7 -print | grep -Fxvf file.lst

What the flags mean:

标志意味着什么:

-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


3  

Pipe the find-command to grep using the -v and -f switches

使用-v和-f开关将find-command传递给grep

find -mtime +7 -print | grep -vf file.lst > found.lst

grep options:

grep选项:

-v : invert the match
-f file: - obtains patterns from FILE, one per line

example:

例:

$ ls
a  b  c  d  file.lst

$ cat file.lst 
a$
b$
c$


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

#1


22  

Pipe your find command through grep -Fxvf:

通过grep -Fxvf管道你的find命令:

find -mtime +7 -print | grep -Fxvf file.lst

What the flags mean:

标志意味着什么:

-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


3  

Pipe the find-command to grep using the -v and -f switches

使用-v和-f开关将find-command传递给grep

find -mtime +7 -print | grep -vf file.lst > found.lst

grep options:

grep选项:

-v : invert the match
-f file: - obtains patterns from FILE, one per line

example:

例:

$ ls
a  b  c  d  file.lst

$ cat file.lst 
a$
b$
c$


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