3.2 rsync选项详解

1、创建目录以及文件
#touch 123.txt
#mkdir test1
#cd test1
#touch 1 2 3
#ln -s /root/123.txt ./123.txt       //软链接root下的123.txt 到本目录下名为123.txt
2、使用-a选项,递归方式传输文件,保存原属性。不拷贝软连接的目标文件
#rsync -a test1/  test2/          //同步test1目录下的文件到test2目录下
#ll test2
-rw-r--r-- 1 root root  0 Feb  3 13:58 1
lrwxrwxrwx 1 root root 13 Feb  3 13:58 123.txt -> /root/123.txt
-rw-r--r-- 1 root root  0 Feb  3 13:58 2
-rw-r--r-- 1 root root  0 Feb  3 13:58 3
#rsync -av --no-l test1/ test2/      //递归传输文件但不保留软连接文件
-rw-r--r-- 1 root root  0 Feb  3 13:58 1
-rw-r--r-- 1 root root  0 Feb  3 13:58 2
-rw-r--r-- 1 root root  0 Feb  3 13:58 3
3、使用-L选项,可以把SRC源文件的目标文件拷贝到DST中
#rsync -avL test1/  test2/      //-L同时拷贝目标文件
#ls -l test2/
-rw-r--r-- 1 root root 0 Feb  3 13:58 1
-rw-r--r-- 1 root root 0 Feb  3 14:43 123.txt
-rw-r--r-- 1 root root 0 Feb  3 13:58 2
-rw-r--r-- 1 root root 0 Feb  3 13:58 3
4、使用-u选项,会把DST中比SRC还新的文件排除掉
#touch test2/1
#ll test1/1 test2/1
-rw-r--r-- 1 root root 0 Feb  3 13:58 test1/1
-rw-r--r-- 1 root root 0 Feb  3 15:07 test2/1
#rsync -avu  test1/  test2/      
#ll  test2/  
-rw-r--r-- 1 root root  0 Feb  3 15:07 1
lrwxrwxrwx 1 root root 13 Feb  3 14:44 123.txt -> /root/123.txt
-rw-r--r-- 1 root root  0 Feb  3 13:58 2
-rw-r--r-- 1 root root  0 Feb  3 13:58 3
5、使用--delete选项,删除DST中SRC中没有的文件
#rm -f test1/123.txt
#rsync -av  test1/  test2/
#ll test2/
total 0
-rw-r--r-- 1 root root  0 Feb  3 13:58 1
lrwxrwxrwx 1 root root 13 Feb  3 14:44 123.txt -> /root/123.txt    //链接文件依然存在
-rw-r--r-- 1 root root  0 Feb  3 13:58 2
-rw-r--r-- 1 root root  0 Feb  3 13:58 3
#rsync -av --delete test1/ test2/
#ll test2/
-rw-r--r-- 1 root root 0 Feb  3 13:58 1
-rw-r--r-- 1 root root 0 Feb  3 13:58 2,
-rw-r--r-- 1 root root 0 Feb  3 13:58 3
6、使用--exclude选项,--exclude=文件名,可以万用字符模式*.txt
#touch test1/1.txt test1/2.txt 4
#ll test1/
-rw-r--r-- 1 root root 0 Feb  3 13:58 1
-rw-r--r-- 1 root root 0 Feb  3 15:27 1.txt
-rw-r--r-- 1 root root 0 Feb  3 13:58 2
-rw-r--r-- 1 root root 0 Feb  3 15:27 2.txt
-rw-r--r-- 1 root root 0 Feb  3 13:58 3
-rw-r--r-- 1 root root 0 Feb  3 15:30 4
#ll test2/
-rw-r--r-- 1 root root 0 Feb  3 13:58 1
-rw-r--r-- 1 root root 0 Feb  3 13:58 2
-rw-r--r-- 1 root root 0 Feb  3 13:58 3
#rsync -a --exclude="*.txt" test1/  test2/    //使用--exclude排除*.txt文件
#ll test2/
-rw-r--r-- 1 root root 0 Feb  3 13:58 1
-rw-r--r-- 1 root root 0 Feb  3 13:58 2
-rw-r--r-- 1 root root 0 Feb  3 13:58 3
-rw-r--r-- 1 root root 0 Feb  3 15:30 4


转载于:https://my.oschina.net/vpirate/blog/614262

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值