发布网友 发布时间:2022-04-21 12:56
共1个回答
热心网友 时间:2022-04-15 02:09
linux下快速删除大量文件假如你要在linux下删除大量文件,比如100万、1000万,像/var/spool/clientmqueue/的mail邮件,像/usr/local/nginx/proxy_temp的nginx缓存等,那么rm -rf *可能就不好使了。rsync提供了一些跟删除相关的参数 rsync --help grep delete --del an alias for --delete-ring --delete delete files that don't exist on the sending side --delete-before receiver deletes before transfer (default) --delete-ring receiver deletes ring transfer, not before --delete-after receiver deletes after transfer, not before --delete-excluded also delete excluded files on the receiving side --ignore-errors delete even if there are I/O errors --max-delete=NUM don't delete more than NUM files其中--delete-before 接收者在传输之前进行删除操作可以用来清空目录或文件,如下:1、先建立一个空目录mkdir /data/blank2、用rsync删除目标目录rsync --delete-before -d /data/blank/ /var/spool/clientmqueue/这样目标目录很快就被清空了又假如你有一些特别大的文件要删除,比如nohup.out这样的实时更新的文件,动辄都是几十个G上百G的,也可 以用rsync来清空大文件,而且效率比较高1、创建空文件touch /data/blank.txt2、用rsync清空文件rsync -a --delete-before --progress --stats /root/blank.txt /root/nohup.outbuilding file list ...1 file to considerblank.txt 0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)Number of files: 1Number of files transferred: 1Total file size: 0 bytesTotal transferred file size: 0 bytesLiteral data: 0 bytesMatched data: 0 bytesFile list size: 27File list generation time: 0.006 secondsFile list transfer time: 0.000 secondsTotal bytes sent: 73Total bytes received: 31 sent 73 bytes received 31 bytes 208.00 bytes/sectotal size is 0 speep is 0.00tips:当SRC和DEST文件性质不一致时将会报错当SRC和DEST性质都为文件【f】时,意思是清空文件内容而不是删除文件当SRC和DEST性质都为目录【d】时,意思是删除该目录下的所有文件,使其变为空目录最重要的是,它的处理速度相当快,处理几个G的文件也就是秒级的事最核心的内容是:rsync实际上用的就是替换原理作者 张慧