Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 查找不在列表中的文件_Linux_Bash_Command Line_Find_Diff - Fatal编程技术网

Linux 查找不在列表中的文件

Linux 查找不在列表中的文件,linux,bash,command-line,find,diff,Linux,Bash,Command Line,Find,Diff,我在file.lst中有一个文件列表。 现在,我想查找目录dir中所有超过7天的文件,除了file.lst文件中的文件。如何修改find命令或从结果中删除file.lst中的所有条目 例如: file.lst: a b c a d e 执行: find -mtime +7 -print > found.lst found.lst: a b c a d e 因此,我所期望的是: d e 使用-v和-f开关将find命令输送到grep find -mtime +7 -print |

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

例如:

file.lst

a
b
c
a
d
e
执行:

find -mtime +7 -print > found.lst
found.lst

a
b
c
a
d
e
因此,我所期望的是:

d
e

使用
-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
a  b  c  d  file.lst

$ cat file.lst 
a$
b$
c$


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

通过
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.

我认为这将匹配大多数情况。但是,如果有一个文件名为“aa”,则可能会匹配fail@ajreal,则可能使用file.lst中的
a$
来缩小该范围possibility@Fredrik:您应该使用固定字符串模式<代码> GRIP-F或<代码> FGRP还考虑添加<代码> -X/COD>选项,除了使用<代码> FGRP。这会起作用吗?cwd中文件
a
find
的输出是
/a
,这将导致
-Fx
无法匹配…如果我需要动态构建文件列表,例如使用
ssh xyz.com'ls/var/backups/daily | tail-10'
,该怎么办?这将取代file.lst中的文件名列表。我在这里试过吹管,但不太清楚(我的吹管功能很弱)。