如何查找除给定名称之外的文件? [英] How to find files except given name?
本文介绍了如何查找除给定名称之外的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个目录包含以下文件:
There is a directory containing the following files:
.
├── bla-bla-bla1.tar.7z
├── bla-bla-bla2.tar.7z
├── bla-bla-bla3.tar.7z
└── _bla-bla-bla_foo.tar.7z
我需要找到并删除所有*.7z
格式的文件,除了_*.7z
I need to find and delete all of the files that in the format of *.7z
except _*.7z
我试过了:
find /backups/ -name "*.7z" -type f -mtime +180 -delete
我该怎么做?
推荐答案
另一种方法是使用带有 find
的附加否定主节点:
Another approach is to use an additional, negated primary with find
:
find /backups/ -name "*.7z" ! -name '_*.7z' -type f -mtime +180 -delete
其他答案中的简单正则表达式更适合您的用例,但这演示了一种更通用的方法,使用 !
运算符可用于 find
.
The simple regex in the other answers is better for your use case, but this demonstrates a more general approach using the !
operator available to find
.
这篇关于如何查找除给定名称之外的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文