假设我想复制一个目录的内容,不包括名称中包含“音乐”一词的文件和文件夹。
cp [exclude-matches] *Music* /target_directory
应该用什么代替 [exclude-matches] 来实现这一点?
最佳答案
在 Bash 中,您可以通过启用 extglob
选项来实现,就像这样(将 ls
替换为 cp
并添加目标目录,当然)
~/foobar> shopt extglob
extglob off
~/foobar> ls
abar afoo bbar bfoo
~/foobar> ls !(b*)
-bash: !: event not found
~/foobar> shopt -s extglob # Enables extglob
~/foobar> ls !(b*)
abar afoo
~/foobar> ls !(a*)
bbar bfoo
~/foobar> ls !(*foo)
abar bbar
您稍后可以禁用 extglob
shopt -u extglob
关于bash - 在 unix/linux shell 中进行模式匹配时如何使用反向或负通配符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/216995/