bash 如何删除以特定字母开头的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7874891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove files starting with a particular letter
提问by LordDoskias
I want to rm all files in a directory not starting with the letter I or N - what is the easiest way to do it in bash?
我想 rm 目录中不以字母 I 或 N 开头的所有文件 - 在 bash 中最简单的方法是什么?
回答by Mark Longair
You can do the following:
您可以执行以下操作:
rm [^IN]*
The [^IN]is a pattern that matches any character except Ior N- this syntax is described in the Pattern Matchingsection of the bash manual.
的[^IN]是,匹配任何字符以外的图案I或N-该语法在描述模式匹配bash的手动部分。
回答by vicentazo
Another way:
其它的办法:
find . -maxdepth 1 -type f -name "[^NI]*" -delete
Obviously, this option is worse ;)
显然,这个选项更糟;)

