linux - linux命令中的方括号后跟感叹号是什么意思?

标签 linux ubuntu terminal command

我找到了以下 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/

相关文章:

linux - 从ubuntu中的程序输出结果中获取特定数据

unicode - 垂直虚线ASCII或Unicode字符

c - 让父进程等待其子进程的正确方法是什么?

linux - 确切地说,为什么 uname -m 在 Sun Grid Engine (SGE) 运行时会报告错误的体系结构?

linux - 从 linux 用户空间访问以太网 phy 驱动程序

linux - grep 命令用于查找包含 "String1"而不是 "String2"的文件

python - 通过 python 进行多人游戏

linux - 如何循环传输管道中的数据?

apache - apache2(2.4.7 Ubuntu 14.04 LTS)中的 ProxyPass worker 主机名太长,如何解决这个问题?

ubuntu - 终端窗口不工作 Ubuntu