So, you can use the
* as a wild card for all files when using
cp within context of a directory. Is there a way to copy all files except
This isn't a feature of
cp, it's a feature of your shell (it expands the
* to mean all non-dot files), so the answer depends on which shell you're using. For example,
zsh supports this syntax:
$ cp ^x /path/to/destination
^x means "all files except
You can also combine selection and de-selection patterns, e.g. to copy all wav files except those containing xyz, you can use:
Could also be done in plain old (portable/compatible) bourne shell in a variety of ways with standard tools in a lot less elegant ways than using advanced shell globbing or commands with built-in-exclusion options.
If there are not too many files (and not with names including spaces and/or linebreaks), this could be a way:
cp `ls | egrep -v '^excludename$'` destdir/.
bash and GNU tools are great and powerful, but they're still not always available. If you intend to put it in a portable script, I would recommend
find as in the comment by Rush.