How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?

前端 未结 11 1604
梦如初夏
梦如初夏 2020-11-22 13:50

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_direc         


        
11条回答
  •  花落未央
    2020-11-22 14:19

    In bash, an alternative to shopt -s extglob is the GLOBIGNORE variable. It's not really better, but I find it easier to remember.

    An example that may be what the original poster wanted:

    GLOBIGNORE="*techno*"; cp *Music* /only_good_music/
    

    When done, unset GLOBIGNORE to be able to rm *techno* in the source directory.

提交回复
热议问题