我如何使用逆或负通配符时模式匹配在Unix / Linux下的壳呢? [英] How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?

查看:122
本文介绍了我如何使用逆或负通配符时模式匹配在Unix / Linux下的壳呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我要复制的目录中排除文件和文件夹的名称中包含单词'音乐'的内容

Say I want to copy the contents of a directory excluding files and folders whose names contain the word 'Music'.

cp [exclude-matches] *Music* /target_directory

我应该去的地方[排除百搭]的做到这一点?

What should go in place of [exclude-matches] to accomplish this?

推荐答案

在bash,那么你可以通过启用extglob选项,这样做(LS替换为CP,并添加目标目录,当然)

In Bash you can do it by enabling the extglob option, like this (replace ls for cp and add the target directory, of course)

~/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

您可以稍后用

shopt -u extglob

这篇关于我如何使用逆或负通配符时模式匹配在Unix / Linux下的壳呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆