linux根据文件名模式搜索文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11043878/
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
linux search file based on file name pattern
提问by crchin
I want to search a series of files based on the files name.
我想根据文件名搜索一系列文件。
Here is my directory :
这是我的目录:
For example I had the file on above.
例如我有上面的文件。
I only want to search out the file which is without _bak.
我只想搜索没有_bak的文件。
采纳答案by Tim Pote
If you're wanting to limit your search to the current directory, use:
如果您想将搜索限制在当前目录,请使用:
find . -maxdepth 1 -mindepth 1 ! -name '*_bak'
If you want to recursively find in all directories remove the -maxdepth 1
.
如果要在所有目录中递归查找,请删除-maxdepth 1
.
Edit in response to OP's comment
编辑以回应 OP 的评论
To get files that begin with ei
and do not end with _bak
use:
要获取ei
以_bak
use开头且不以use结尾的文件:
find . -type f -name 'ei*' -a ! -name '*_bak'
回答by Erwald
Use the Grep Invert Match option.
使用 Grep 反转匹配选项。
For example, if you want all the file without the word _bak, use :
例如,如果您想要没有 _bak 一词的所有文件,请使用:
grep -v *_bak /path/to/file
回答by AzizSM
Please try this :
请试试这个:
find . -type f ! -iname "*_bak"
The above command will find all files that have not end with _bak.
上面的命令将查找所有不以 _bak 结尾的文件。