Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to skip the specified directory when Linux synchronizes files with cp and rsync

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "Linux synchronizes files with cp and rsync how to skip the specified directory" related knowledge, Xiaobian shows you the process of operation through an actual case, the method of operation is simple and fast, and practical, I hope that this article "Linux synchronizes files with cp and rsync how to skip the specified directory" article can help you solve the problem.

The requirement is: a test site needs to be synchronized to the official site at a certain node, but the config directory in it cannot be overwritten.

Method 1: execute the following command under the terminal command line

Cp-r `find / projecta-type d-path / projecta/common/config-prune-o-print | sed 1d` / projectb/

Method 2:

Localhost # find projectb/ommon/config | xargs touch modifies the access time of the congfig directory files in the target directory to the current, so that the cp can be avoided by adding the update parameter.

Localhost # cp-r-u-v projecta/* projectb/ will no longer copy the hidden directory of the first level under projecta, but the second and third level will still copy it.

Therefore, it is more convenient when there is no hidden directory.

But because our project involves svn or something, there will be a lot of hidden directories containing version control information, which will be very messy, so there is a second solution.

Method 3:

Rsync-vaup-exclude= ". *"-exclude= "common/config" projecta/ projectb

A simple comment

-a parameter, equivalent to-rlptgod,-r is recursive-l is a linked file, meaning to copy a linked file;-p means to keep the original permissions of the file;-t to keep the original time of the file;-g to keep the original user group of the file;-o to keep the original owner of the file;-d is equivalent to the block device file.

-p transmission progress

-v redundancy mode, view file list, etc.

-u update mode, skipping if the destination file is new than the source file

The first exclude means to skip all. Hidden file at the beginning

The second indicates that the projecta/common/config directory has been transferred, because the files in the config directory do not need to be changed easily. If you need to adjust them manually, note that this parameter is the relative path of the following src parameter.

This is the end of the content about "how to skip the specified directory when Linux synchronizes files with cp and rsync". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report