linux刪除大量文件的6種方法
首先建立50萬個(gè)文件
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
由于文件數(shù)量過多,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
用時(shí)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,很好很強(qiáng)大。
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
大概用時(shí)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
相關(guān)文章
如何使用 Shell 腳本執(zhí)行 .NET Core 應(yīng)用
這篇文章主要介紹了如何使用 Shell 腳本執(zhí)行 .NET Core 應(yīng)用,幫助大家更好的理解和使用shell 腳本,感興趣的朋友可以了解下2020-09-09如何使用shell獲取進(jìn)程名的內(nèi)存以及CPU利用率
最近工作中遇到一個(gè)需求,需要找出占用高的進(jìn)程,所以下面這篇文章主要給大家介紹了關(guān)于如何使用shell獲取進(jìn)程名的內(nèi)存以及CPU利用率的相關(guān)資料,需要的朋友可以參考下2022-04-04shell腳本之判斷輸入?yún)?shù)是否為整數(shù)值的實(shí)例
今天小編就為大家分享一篇shell腳本之判斷輸入?yún)?shù)是否為整數(shù)值的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-07-07一篇教會(huì)你寫90%的shell腳本(入門小結(jié))
這篇文章主要介紹了一篇教會(huì)你寫90%的shell腳本,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05Linux Shell中curl和wget使用代理IP的方法教程
這篇文章主要給大家介紹了關(guān)于在Linux Shell中curl和wget使用代理IP的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08Shell腳本實(shí)現(xiàn)獲取網(wǎng)頁(yè)快照并生成縮略圖
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)獲取網(wǎng)頁(yè)快照并生成縮略圖,本文獲取網(wǎng)頁(yè)快照使用phantomjs、生成縮略圖使用ImageMagick,需要的朋友可以參考下2015-02-02