假设我想复制目录的内容,不包括名称中包含“音乐”一词的文件和文件夹。
cp [exclude-matches] *Music* /target_directory
应该用什么来代替 [exclude-matches] 来实现此目的?
在 Bash 中,您可以通过启用extglob
选项,像这样(替换ls
with 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)