从查找中排除文件列表 [英] Exclude list of files from find
本文介绍了从查找中排除文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果在运行 find
时要排除的文本文件中有文件名列表,该怎么办?例如,我想做类似的事情:
If I have a list of filenames in a text file that I want to exclude when I run find
, how can I do that? For example, I want to do something like:
find /dir -name "*.gz" -exclude_from skip_files
并获得/dir中的所有.gz文件,但skip_files中列出的文件除外.但是find没有 -exclude_from
标志.如何跳过 skip_files
中的所有文件?
and get all the .gz files in /dir except for the files listed in skip_files. But find has no -exclude_from
flag. How can I skip all the files in skip_files
?
推荐答案
我不认为 find
有这样的选项,您可以使用 printf
来构建命令和您的排除列表:
I don't think find
has an option like this, you could build a command using printf
and your exclude list:
find /dir -name "*.gz" $(printf "! -name %s " $(cat skip_files))
与做的相同:
find /dir -name "*.gz" ! -name first_skip ! -name second_skip .... etc
或者,您也可以从 find
到 grep
:
find /dir -name "*.gz" | grep -vFf skip_files
这篇关于从查找中排除文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文