简体   繁体   English

如何排除一些文件

[英]How to exclude some files

I have files default.attr, default.ba. 我有文件default.attr,default.ba。 default.cir .. I want to remove all default.* files except default.cir in linux. default.cir ..我要删除Linux中default.cir以外的所有default。*文件。

Use ! 使用! in find : find

find . -name "default.*" -a \! -name "default.cir" -print

After checking that this works as expected, you can replace -print with -delete . 在检查到它可以正常工作后,可以将-print替换为-delete

The simplest and probably safest way is to just move the files you don't want to delete to a different directory, perform your operations, and move the files back: 最简单且可能最安全的方法是将不想删除的文件移到另一个目录,执行操作,然后将文件移回:

TMPDIR=$(mktemp -d)
mv default.cir $TMPDIR/
rm default.*
mv $TMPDIR/* .
rmdir $TMPDIR

This way you don't have to create any complex command and it will work with an arbitrary number of files. 这样,您不必创建任何复杂的命令,它便可以处理任意数量的文件。

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

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