秒删海量数据文件的方法


在运维的工作中、有时我们需要去删除大文件、或者 N (N 取正无穷哟~~)多小文件

那么、rm 次奥咯、

这里、Rocky 介绍 Linux 史上最可爱、最温柔、最成熟、最善良、最.....槽糕、找不到形容词、囧

那便是 rsync 的另外一种用法

① 语法:

# rsync --delete-before -avH --progress --stats DEST SRC

解释:

当SRC和DEST性质都为文件【f】时,意思是清空文件内容而不是删除文件

当SRC和DEST性质都为目录【d】时,意思是删除该目录下的所有文件,使其变为空目录

PS:其实该命令顶好记的哦、av -_-#、H$_$、男人很少不懂的、骚年、此时你的硬盘都有谁来着、、

② 原理:

rsync实际上用的就是替换原理

③ 优点:

处理速度相当快,处理几个G的文件也就是秒级的事、比rm要快很多倍

④ 缺点:

对磁盘io的占用较高、业务高峰或要暂避

⑤ 测试:

[root@localhost log]# ls
rhel-server-5.8-i386-dvd.iso
[root@localhost log]# pwd
/tmp/test/log
[root@localhost ~]# mkdir empty
[root@localhost ~]# rsync --delete-before -avH --progress --stats /root/empty/ /tmp/test/log/
building file list ...
1 file to consider
deleting rhel-server-5.8-i386-dvd.iso
./

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  6.77 bytes/sec
total size is 0  speedup is 0.00

推荐阅读:

rsync同步完整配置

利用rsync工具进行同步Windows和Linux机器之间的文件

Rsync+inotify 组合使用同步方案

Rsync和inotify文件实时备份配置

CentOS 5.5下Rsync使用技巧与权限问题解读

相关内容

    暂无相关文章