日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux rm 删除所有文件,linux无需rm就可快速删除大量文件

發布時間:2025/3/19 linux 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux rm 删除所有文件,linux无需rm就可快速删除大量文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

格式:

rsync --delete-before -a -H -v --progress --stats

選項:

--delete-before??? 接收者在傳輸之前進行刪除操作

-progress???? 在傳輸時顯示傳輸過程

-a?????? 歸檔模式 表示以遞歸方式傳輸文件,并保持所有文件屬性

-r??????? 對子目錄以遞歸方式處理

-H????? 保持硬連接的文件

-v?????? 詳細輸出模式

舉例說明:

/home/aniya/ 是一個空文件夾【無任何子目錄以及文件】,/home/zhaoyj目錄下有很多文件,現在要將這個目錄下的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

---------------------------------------------------------------------------------------------------------------------------------------------

當源和目的文件性質不一致的時候會報錯的:

[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的壓縮包,現在是把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是否還存在,查看結果是存在的,但是包的大小變為了0

[root@XKWB5705 /]# ls -l /aniya/

total 0

-rw-r--r-- 1 root root 0 Sep 15 21:22 usr.tar.gz

-----------------------------------------------------------------------------------------------------------------------------------------------

現在清空/varOLD下的文件,使其變為空目錄:

[root@XKWB5705 /]# rm -rvf /varOLD/hahah

removed `/varOLD/hahah'

[root@XKWB5705 /]# ls /varOLD/

我現在要做的是將/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/目錄已經為空了

[root@XKWB5705 /]# ls /aniya/

[root@XKWB5705 /]# ls /aniya/

從以上結果可以得知:

當SRC和DEST文件性質不一致時將會報錯

當SRC和DEST性質都為文件【f】時,意思是清空文件內容而不是刪除文件

當SRC和DEST性質都為目錄【d】時,意思是刪除該目錄下的所有文件,使其變為空目錄

最重要的是,它的處理速度相當快,處理幾個G的文件也就是秒級的事

最核心的內容是:rsync實際上用的就是替換原理

摘自:ANLJF的專欄

總結

以上是生活随笔為你收集整理的linux rm 删除所有文件,linux无需rm就可快速删除大量文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。