Bash Command – How to Copy Some, But Not All Files

bashshellwildcards

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 x file?

Best Answer

In bash you can use extglob:

 $ shopt -s extglob  # to enable extglob
 $ cp !(b*) new_dir/

where !(b*) exclude all b* files.

You can later disable extglob with

 $ shopt -u extglob