How to copy some, but not all files?
Rsync handles this nicely.
Example copy all: rsync -aP /folder1/* /folder/2
Example copy all with exclusion: rsync -aP --exclude=x /folder1/* /folder2/
The -aP
switch:
a
: Similar tocp -a
, recursive, etc.P
: Shows progress, a nice feature of rsync.
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
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
Where ^x
means "all files except x
"
You can also combine selection and de-selection patterns, e.g. to copy all wav files except those containing xyz, you can use:
cp *.wav~*xyz*