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

Source: Internet
Author: User
Tags 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

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.