Linux method to skip a specified directory when synchronizing files with cp and rsync

  • 2020-05-06 12:07:14
  • OfStack

The requirement is: a test site needs to synchronize to the official site at a certain node, but the config directory inside cannot overwrite


Method 1: from the terminal command line, execute the following command
cp -R `find /projectA -type d -path /projectA/common/config -prune -o -print | sed 1d ` /projectB/

method 2:

localhost # find projectB/ommon/config | localhost # cp-r-u-v /* projectB/ this will not duplicate projectA's level 1 hidden directory, but level 2 and level 3 will still copy

So it is convenient to use without hidden directory.

But our project would have a lot of hidden directories with version control information because of SVN, so it would be messy. So we have a second option,

method 3:

Es52en-vauP --exclude=".* "--exclude=" common/config "projectA/ projectB

Just a quick comment on
-a, equivalent to -rlptgoD, -r is recursive -l is a link file, which means to copy a link file; -p means to keep the original permission of the file; -t keep documents as they are; -g maintains the original user group of the file; -o maintains the original ownership of the document; -D equivalent to block device file;
-P transmission schedule;
-v redundancy mode, view to file list
etc -u update mode,
is skipped if the destination file is new to the source file The first exclude means to skip all. The beginning of the hidden file
The second means that the projectA/common/config directory has been called, because the files in the config directory do not need to be changed easily. If manual adjustment is needed, please note that this parameter is the relative path of the SRC parameter

Related articles: