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