The implementation method of excluding one or more directories when the CP directory is under Linux

Source: Internet
Author: User
Tags command line rsync

Description: / home directory with data directory, data directory with A, B, C, D, E Five directories, now copy all directories except the e directory in the data directory to the /bak directory

Method One: The Terminal command line executes the following command

cp-r ' find/home/data-type d-path/home/data/e-prune-o-print | sed 1 d '/bak
########################################################
Script implementation
Script Store path/home/osyunwei.sh
vi/home/osyunwei.sh #编辑脚本, add the following code
#!/bin/sh
cp-r ' find/home/data-type d-path/home/data/e-prune-o-print | sed 1d '/bak
Chmo D +x/home/osyunwei.sh #添加脚本执行权限
cd/home #进入脚本存放目录
./osyunwei.sh #执行脚本
span>########################################################

Method Two: When replicating with the CP command, only one directory is excluded from replication , if you want to exclude two or more directories, you need to use the rsync command to implement, see the following example

If you want to exclude the/home/data directory of A,b, C, three directories, copy all other directories at the same time, execute the following command
yum install rsync #安装rsync
rsync-av--exclude data/a-- Exclude data/b--exclude data/c data/bak

Note: The path after the--exclude cannot be an absolute path, it must be a relative path, or an error occurs.

Original from http://www.osyunwei.com

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.