简体   繁体   English

bash中点的通配符是什么?

[英]What's the wildcard for dot in bash?

I have files like 0001.file1.email.data.spam.txt and 0001.file1.email.data.spam_1.txt 我有类似0001.file1.email.data.spam.txt和0001.file1.email.data.spam_1.txt的文件

Now I want to delete all files end with "_1.txt", I tried to use "rm -rf *spam_1.txt", but it cannot find the files. 现在,我想删除所有以“ _1.txt”结尾的文件,我尝试使用“ rm -rf * spam_1.txt”,但是找不到文件。 Maybe because * cannot viewed as dot. 可能是因为*无法视为点。

Dot is a literal character which simply matches itself. 点是一个文字字符,仅与之匹配。

The * wildcard matches any sequence of characters, and the ? *通配符匹配任何字符序列,而? wildcard matches any single character, but wildcard matching will ignore files which start with a dot unless you have dotglob enabled (it is off by default). 通配符匹配任何单个字符,但是通配符匹配将忽略以点开头的文件,除非您启用了dotglob (默认情况下处于关闭状态)。

You can easily examine what files are being matched by a wildcard expression with something like 您可以轻松检查通配符表达式匹配哪些文件,例如

printf '>>%s<<\n' *spam_1.txt

(The >> ... << decoration is just to make it easy to see any leading or trailing whitespace, and isn't strictly necessary.) >> ... <<装饰只是为了易于查看任何前导或尾随空白,而并非必须如此。)

In the absence of nullglob , the above will print the wildcard itself if it doesn't find any matches. 在没有nullglob的情况下,如果找不到任何匹配项,则上面的代码将打印通配符本身。 Also check out failglob which causes an error to be printed and the command to be aborted if the wildcard doesn't match anything. 如果通配符不匹配,还请检查一下failglob ,这会导致打印错误并中止命令。

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

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