先建立50萬個檔案:
test for i in $(seq 1 500000) for> do for> echo test >>$i.txt for> done
1.rm
test time rm -f * zsh: sure you want to delete all the files in /home/hungerr/test [yn]? y zsh: argument list too long: rm rm -f * 3.63s user 0.29s system 98% cpu 3.985 total
因為檔案數量過多,rm不起作用。
2.find
test time find ./ -type f -exec rm {} \; find ./ -type f -exec rm {} \; 49.86s user 1032.13s system 41% cpu 43:19.17 total
大概43分鐘。
3.find with delete
test time find ./ -type f -delete find ./ -type f -delete 0.43s user 11.21s system 2% cpu 9:13.38 total
用時9分鐘。
4.rsync
先建立空資料夾blanktest
~ time rsync -a --delete blanktest/ test/ rsync -a --delete blanktest/ test/ 0.59s user 7.86s system 51% cpu 16.418 total
16s,很好很強大。
5.Python
import os import time stime=time.time() for pathname,dirnames,filenames in os.walk('/home/username/test'): for filename in filenames: file=os.path.join(pathname,filename) os.remove(file) ftime=time.time() print ftime-stime
~ python test.py 494.272291183
大概用時8分鐘。
6.Perl
test time perl -e 'for(<*>){((stat)[9]<(unlink))}' perl -e 'for(<*>){((stat)[9]<(unlink))}' 1.28s user 7.23s system 50% cpu 16.784 total
以上是linux刪除檔案的6種方法(總結)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Linux系統的五大支柱是:1.內核,2.系統庫,3.Shell,4.文件系統,5.系統工具。內核管理硬件資源並提供基本服務;系統庫為應用程序提供預編譯函數;Shell是用戶與系統交互的接口;文件系統組織和存儲數據;系統工具用於系統管理和維護。

在Linux系統中,可以通過在啟動時按特定鍵或使用命令如“sudosystemctlrescue”進入維護模式。維護模式允許管理員在不受干擾的情況下進行系統維護和故障排除,如修復文件系統、重置密碼、修補安全漏洞等。

Linux初學者應掌握文件管理、用戶管理和網絡配置等基本操作。 1)文件管理:使用mkdir、touch、ls、rm、mv、cp命令。 2)用戶管理:使用useradd、passwd、userdel、usermod命令。 3)網絡配置:使用ifconfig、echo、ufw命令。這些操作是Linux系統管理的基礎,熟練掌握它們可以有效管理系統。

本文解釋瞭如何管理Linux中的Sudo特權,包括授予,撤銷和安全性最佳實踐。關鍵重點是安全和sudoers安全和限制訪問。Character數量:159

本文提供了有關使用Google Authenticator在Linux上設置兩因素身份驗證(2FA)的指南,詳細介紹了安裝,配置和故障排除步驟。它突出了2FA的安全益處,例如增強的SEC

本文討論了使用TOP,HTOP和VMSTAT監視Linux系統性能,並詳細介紹其獨特功能和自定義選項,以進行有效的系統管理。

文章討論了使用APT,YUM和DNF在Linux中管理軟件包,涵蓋安裝,更新和刪除。它比較了它們對不同分佈的功能和適用性。

本文介紹瞭如何在Linux中使用正則表達式(REGEX)進行模式匹配,文件搜索和文本操作,詳細列式,命令和工具,例如GREP,SED和AWK。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

WebStorm Mac版
好用的JavaScript開發工具

禪工作室 13.0.1
強大的PHP整合開發環境

Atom編輯器mac版下載
最受歡迎的的開源編輯器