简体   繁体   English

为什么 ''rm *(1)*'' 可以删除名称中不包含字符串“(1)”的文件?

[英]Why can ''rm *(1)*'' delete files which do not contain the string "(1)" in their names?

I used the rm command in my downloads folder (windows subsystem for linux).我在我的下载文件夹(Linux 的 Windows 子系统)中使用了 rm 命令。 although I told it to delete anything with (1) within it, all the files in the downloads folder were removed.尽管我告诉它删除其中包含 (1) 的任何内容,但下载文件夹中的所有文件都已删除。 Why would this have occurred?为什么会发生这种情况?

rm *(1)*

*(...) is extglob syntax for "zero or more of ... ". *(...)是“零个或多个... ”的extglob 语法

Thus, you told your shell to pass rm an argument list consisting of all file which start with zero or more 1 s, and then have any suffix following.因此,您告诉您的 shell 向rm传递一个参数列表,该列表由所有以零个或多个1开头的文件组成,然后有任何后缀。 Every possible filename matches this pattern, so the result is equivalent to rm * .每个可能的文件名都与此模式匹配,因此结果等效于rm *


If you want to be certain that a substring is literal rather than treated as glob syntax, always quote it:如果你想确定一个子字符串是文字而不是作为 glob 语法处理,总是引用它:

rm -- *'(1)'*

...is going to behave consistently on all POSIX-superset systems, including ones that implement extglob -like extensions. ...将在所有 POSIX 超集系统上表现一致,包括实现extglob类扩展的系统。

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

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