Is there a way to use command 'cp' to copy a directory and exclude certain files/sub-directories within it?
Command Line – cp Command to Exclude Certain Files from Being Copied
bashcommand linecp
bashcommand linecp
Is there a way to use command 'cp' to copy a directory and exclude certain files/sub-directories within it?
Best Answer
Use
rsync
:Note that using
source
andsource/
are different. A trailing slash means to copy the contents of the foldersource
intodestination
. Without the trailing slash, it means copy the folder source intodestination
.Alternatively, if you have lots of directories (or files) to exclude, you can use
--exclude-from=FILE
, whereFILE
is the name of a file containing files or directories to exclude.--exclude
may also contain wildcards, such as--exclude=*/.svn*
Copied From: https://stackoverflow.com/a/2194500/749232
If you want to use
cp
itself:This assumes the target directory structure is the same as the source's.
Copied From: https://stackoverflow.com/a/4586025/749232