- A+
所属分类:未分类
格式: rsync --delete-before -a -H -v --progress --stats 选项: --delete-before 接收者在传输之前进行删除操作 -progress 在传输时显示传输过程 -a 归档模式 表示以递归方式传输文件,并保持所有文件属性 -r 对子目录以递归方式处理 -H 保持硬连接的文件 -v 详细输出模式
举例说明:
/root/345/ 是一个空文件夹,/root/k8s_images目录下有很多文件,现在要将这个目录下的N多个文件清空
[root@bogon ~]# du -sh *
0 345
1.2G k8s_images
然后执行命令
[root@bogon ~]# rsync --delete-before -a -H -v --progress --stats /root/345/ /root/k8s_images
building file list ...
1 file to consider
deleting docker_images/pause-amd64_3.0.tar
deleting docker_images/kubernetes-dashboard_v1.8.1.tar
deleting docker_images/kube-scheduler-amd64_v1.9.0.tar
deleting docker_images/kube-proxy-amd64_v1.9.0.tar
deleting docker_images/kube-controller-manager-amd64_v1.9.0.tar
deleting docker_images/kube-apiserver-amd64_v1.9.0.tar
deleting docker_images/k8s-dns-sidecar-amd64_1.14.7.tar
deleting docker_images/k8s-dns-kube-dns-amd64_1.14.7.tar
deleting docker_images/k8s-dns-dnsmasq-nanny-amd64_v1.14.7.tar
deleting docker_images/flannel_v0.9.1-amd64.tar
deleting docker_images/etcd-amd64_v3.1.10.tar
deleting docker_images/
deleting yum-utils-1.1.31-42.el7.noarch.rpm
deleting socat-1.7.3.2-2.el7.x86_64.rpm
deleting python-kitchen-1.1.1-5.el7.noarch.rpm
deleting lvm2-libs-2.02.171-8.el7.x86_64.rpm
deleting lvm2-2.02.171-8.el7.x86_64.rpm
deleting lsof-4.87-4.el7.x86_64.rpm
deleting libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
deleting libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm
deleting libseccomp-2.3.1-3.el7.x86_64.rpm
deleting kubernetes-dashboard_v1.8.1.tar
deleting kubernetes-dashboard.yaml
deleting kubernetes-cni-0.6.0-0.x86_64.rpm
deleting kubelet-1.9.9-9.x86_64.rpm
deleting kubectl-1.9.0-0.x86_64.rpm
deleting kubeadm-1.9.0-0.x86_64.rpm
deleting kube-flannel.yml
deleting docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
deleting docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
deleting device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64.rpm
deleting device-mapper-libs-1.02.140-8.el7.x86_64.rpm
deleting device-mapper-event-libs-1.02.140-8.el7.x86_64.rpm
deleting device-mapper-event-1.02.140-8.el7.x86_64.rpm
deleting device-mapper-1.02.140-8.el7.x86_64.rpm
deleting container-selinux-2.33-1.git86f33cd.el7.noarch.rpm
./
Number of files: 1
Number of files transferred: 0
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 19
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 29
Total bytes received: 15
sent 29 bytes received 15 bytes 88.00 bytes/sec
total size is 0 speedup is 0.00
--------------------------------------------------------------------------------------------------------------
这个命令必须是目录对目录,文件对文件,如果岔了就报错:
[root@bogon ~]# rsync --delete-before -a -H -v --progress --stats /root/345/ /root/k8s_images.tgz
building file list ...
1 file to consider
ERROR: cannot overwrite non-directory with a directory
rsync error: errors selecting input/output files, dirs (code 3) at main.c(559) [Receiver=3.0.9]
rsync: connection unexpectedly closed (9 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]
[root@bogon ~]#
--------------------------------------------------------------------------------------------------------------
现在我们再演示一下删除大文件,如下
[root@bogon ~]# touch 123 [root@bogon ~]# du -sh * 0 123 354M k8s_images.tgz
然后执行删除命令,如下:
[root@bogon ~]# rsync --delete-before -a -H -v --progress --stats /root/123 /root/k8s_images.tgz
building file list ...
1 file to consider
123
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)
Number of files: 1
Number of files transferred: 1
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 21
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 67
Total bytes received: 31
sent 67 bytes received 31 bytes 196.00 bytes/sec
total size is 0 speedup is 0.00
查看一下k8s_images.tgz大小
[root@bogon ~]# du -sh *
0 123
0 k8s_images.tgz
--------------------------------------------------------------------------------------------------------------
好了,这样就搞定了
或者用
rsync --delete -rlptD /root/345/ /root/k8s_images
也可以删除,可以自由选择哈
- 安卓客户端下载
- 微信扫一扫
- 微信公众号
- 微信公众号扫一扫