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?
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?
Not in bash (that I know of), but:
I know this is not exactly what you were looking for, but it will solve your example.
One solution for this can be found with find.
Find has quite a few options, you can get pretty specific on what you include and exclude.
Edit: Adam in the comments noted that this is recursive. find options mindepth and maxdepth can be useful in controlling this.
In Bash you can do it by enabling the
extglob
option, like this (replacels
withcp
and add the target directory, of course)You can later disable extglob with
In bash, an alternative to
shopt -s extglob
is theGLOBIGNORE
variable. It's not really better, but I find it easier to remember.An example that may be what the original poster wanted:
When done,
unset GLOBIGNORE
to be able torm *techno*
in the source directory.You can also use a pretty simple
for
loop: