我找到了以下 linux 命令。
cp -f [!r][!e][!d][!m][!i][!n][!e]* /SomePath
我知道
cp
和 -f
也没有问题。但我不知道的是方括号和感叹号的作用([!r]
、[!e]
、[!d]
、[!m]
、[!i]
、[!n]
)。谁能帮我?我在这里找到了这个命令:https://redmine.org/projects/redmine/wiki/HowTo_Migrate_Redmine_to_a_new_server_to_a_new_Redmine_version
最佳答案
这在手册 pattern matching 下进行了描述。 :
[…]
Matches any of the enclosed characters. [...] If the first character following the[
is a!
or a^
then any character not enclosed is matched.
所以,
[!r]
是除 r
之外的任何字符, [!e]
是除 e
之外的任何字符, 等等。 [!r][!e][!d][!m][!i][!n][!e]*
扩展为所有不以字符串 redmine
开头的文件的名称(以 .
开头的除外,除非设置了 dotglob
shell 选项)。还有另一个 shell 选项可以让你写同样的东西更优雅一点:
shopt -s extglob
cp -f !(redmine)* /SomePath
在哪里
!(pattern)
匹配除 pattern
之外的所有内容.
关于linux - linux命令中的方括号后跟感叹号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62215195/