rsync

最近有个文件系统被占用100%, 用rm删除,等了几个小时纹丝不动,根本删不动,上网搜索后发现,当文件过多时,用rm是非常非常慢的。应该用神器rsync

rsync原本用于传输和同步文件/文件夹,可用于本地 ,也可以远程传输,但加上参数后,利用同步机制可以快速删除文件夹

# /root/blank是个空文件夹
# /var/lib/docker是要删除的巨大文件夹
rsync -avz --ignore-existing --recursive --delete /root/blank/ /var/lib/docker/

rsync常用的功能有:

  • 拷贝普通文件:
rsync /opt/file.zip user@12.12.12.12:/var/www/
  • 拷贝文件夹:
rsync -rv /root/myfiles /tmp/myfilesbackup
  • 通过ssh远程拷贝,添加-e参数,可以指定ssh的细节
rsync -r -v -e "ssh -i ~/.ssh/xxx" file user@12.12.12.12:/opt/file

rsync -a -e "ssh -p 3322" file user@12.12.12.12:/var/www/images/

rsync的一些参数:

 rsync -h

-delete - delete files that don't exist on sender (system)
-v - verbose (-vv will provide more detailed information)
-e "ssh options" - specify the ssh as remote shell
-a - archive mode - it preserves permissions (owners, groups), times, symbolic links, and devices
-r - recurse into directories
-z - compress file data during transfer
--exclude 'foldername' – excludes the corresponding folder from transfer
-P – show progress during transfer



《 “rsync” 》 有 4 条评论

  1. can you buy clomid online legally The face of Paulus, captain of the Golden Lion Squadron, has become more and more ugly, and the others have an irrelevant expression, just pretending that they have not seen anything

  2. A tumor presumably originating from the esophagus was detected want to buy priligy in pakistan

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About Me

一位程序员,会弹吉他,喜欢读诗。
有一颗感恩的心,一位美丽的妻子,两个可爱的女儿
mail: geraldlee0825@gmail.com
github: https://github.com/lisuxiaoqi
medium: https://medium.com/@geraldlee0825