linux rm 删除所有文件,linux无需rm就可快速删除大量文件
格式:
rsync --delete-before -a -H -v --progress --stats
選項:
--delete-before??? 接收者在傳輸之前進行刪除操作
-progress???? 在傳輸時顯示傳輸過程
-a?????? 歸檔模式 表示以遞歸方式傳輸文件,并保持所有文件屬性
-r??????? 對子目錄以遞歸方式處理
-H????? 保持硬連接的文件
-v?????? 詳細輸出模式
舉例說明:
/home/aniya/ 是一個空文件夾【無任何子目錄以及文件】,/home/zhaoyj目錄下有很多文件,現(xiàn)在要將這個目錄下的N多個文件清空
[root@XKWB5705 home]# rsync --delete-before -a -H -v --progress --stats? /home/aniya/? /home/zhaoyj
building file list ...
13 files to consider
./
.bash_history
2032 100%??? 0.00kB/s??? 0:00:00 (xfer#1, to-check=11/13)
.bash_logout
33 100%??? 8.06kB/s??? 0:00:00 (xfer#2, to-check=10/13)
.bash_profile
176 100%?? 21.48kB/s??? 0:00:00 (xfer#3, to-check=9/13)
.bashrc
124 100%?? 15.14kB/s??? 0:00:00 (xfer#4, to-check=8/13)
.viminfo
557 100%?? 45.33kB/s??? 0:00:00 (xfer#5, to-check=7/13)
.mozilla/
.mozilla/extensions/
.mozilla/plugins/
Maildir/
Maildir/cur/
Maildir/new/
Maildir/tmp/
Number of files: 13
Number of files transferred: 5
Total file size: 2922 bytes
Total transferred file size: 2922 bytes
Literal data: 2922 bytes
Matched data: 0 bytes
File list size: 297
File list generation time: 0.022 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 3513
Total bytes received: 178
sent 3513 bytes? received 178 bytes? 7382.00 bytes/sec
total size is 2922? speedup is 0.79
---------------------------------------------------------------------------------------------------------------------------------------------
當源和目的文件性質(zhì)不一致的時候會報錯的:
[root@XKWB5705 /]# rsync --delete-before -a -H -v --progress --stats? /varOLD/?? /aniya/usr.tar.gz
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(488) [receiver=2.6.8]
rsync: connection unexpectedly closed (8 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(463) [sender=2.6.8]
[root@XKWB5705 /]# ls -l aniya/
total 1049844
-rw-r--r-- 1 root root 1073982015 Sep 15 21:09 usr.tar.gz
---------------------------------------------------------------------------------------------------------------------------------------------
haha.txt 是空文件,usr.tar.gz是1.1G的壓縮包,現(xiàn)在是把usr.tar.gz的大小由1.1G變成0【即清空文件包】
[root@XKWB5705 /]# touch /varOLD/haha.txt
[root@XKWB5705 /]# rsync --delete-before -a -H -v --progress --stats? /varOLD/haha.txt?? /aniya/usr.tar.gz
building file list ...
1 file to consider
hahah
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: 32
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 90
Total bytes received: 42
sent 90 bytes? received 42 bytes? 88.00 bytes/sec
total size is 0? speedup is 0.00
查看一下usr.tar.gz是否還存在,查看結(jié)果是存在的,但是包的大小變?yōu)榱?
[root@XKWB5705 /]# ls -l /aniya/
total 0
-rw-r--r-- 1 root root 0 Sep 15 21:22 usr.tar.gz
-----------------------------------------------------------------------------------------------------------------------------------------------
現(xiàn)在清空/varOLD下的文件,使其變?yōu)榭漳夸?#xff1a;
[root@XKWB5705 /]# rm -rvf /varOLD/hahah
removed `/varOLD/hahah'
[root@XKWB5705 /]# ls /varOLD/
我現(xiàn)在要做的是將/aniya/目錄下的所有文件清空【即刪除usr.tar.gz文件包】:
[root@XKWB5705 /]# rsync --delete-before -a -H -v --progress --stats? /varOLD/?? /aniya/
building file list ...
1 file to consider
deleting usr.tar.gz
./
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: 28
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 50
Total bytes received: 26
sent 50 bytes? received 26 bytes? 152.00 bytes/sec
total size is 0? speedup is 0.00
/aniya/目錄已經(jīng)為空了
[root@XKWB5705 /]# ls /aniya/
[root@XKWB5705 /]# ls /aniya/
從以上結(jié)果可以得知:
當SRC和DEST文件性質(zhì)不一致時將會報錯
當SRC和DEST性質(zhì)都為文件【f】時,意思是清空文件內(nèi)容而不是刪除文件
當SRC和DEST性質(zhì)都為目錄【d】時,意思是刪除該目錄下的所有文件,使其變?yōu)榭漳夸?/p>
最重要的是,它的處理速度相當快,處理幾個G的文件也就是秒級的事
最核心的內(nèi)容是:rsync實際上用的就是替換原理
摘自:ANLJF的專欄
總結(jié)
以上是生活随笔為你收集整理的linux rm 删除所有文件,linux无需rm就可快速删除大量文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php怎么添加会员卡,怎么在微信公众号中
- 下一篇: linux用户ftp失败,vsftpd本