linux刪除大量文件的6種方法
更新時(shí)間:2014年02月07日 10:08:17 作者:
這篇文章主要介紹了linux刪除大量文件的6種方法,需要的朋友可以參考下
首先建立50萬(wàn)個(gè)文件
復(fù)制代碼 代碼如下:
test for i in $(seq 1 500000)
for> do
for> echo test >>$i.txt
for> done
1 rm
復(fù)制代碼 代碼如下:
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ù)量過(guò)多,rm不起作用。
2 find
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
~ 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
復(fù)制代碼 代碼如下:
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
復(fù)制代碼 代碼如下:
~ python test.py
494.272291183
大概用時(shí)8分鐘。
6 Perl
復(fù)制代碼 代碼如下:
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 刪除文件夾和文件的命令(強(qiáng)制刪除包括非空文件)
- linux實(shí)現(xiàn)除了某個(gè)文件或某個(gè)文件夾以外的全部刪除
- Linux系統(tǒng)刪除文件夾和文件的命令
- Linux中FTP賬號(hào)無(wú)法刪除文件夾的解決方案
- linux服務(wù)器下完美解決無(wú)法刪除虛擬主機(jī)文件或文件夾
- 解析Linux文件夾文件創(chuàng)建、刪除
- Linux 中清空或刪除大文件內(nèi)容的五種方法
- Linux中刪除文件內(nèi)空行的4種方法
- Windows和Linux下定時(shí)刪除某天前的文件的腳本
- Linux中文件/文件夾無(wú)法刪除的解決方案
相關(guān)文章
shell腳本學(xué)習(xí)指南[六](Arnold Robbins & Nelson H
這篇文章主要介紹了shell腳本學(xué)習(xí)指南[六](Arnold Robbins & Nelson H.F. Beebe著),需要的朋友可以參考下2014-02-02
linux下監(jiān)視進(jìn)程 崩潰掛掉后自動(dòng)重啟的shell腳本
如何保證服務(wù)一直運(yùn)行?如何保證即使服務(wù)掛掉了也能自動(dòng)重啟?在寫服務(wù)程序時(shí)經(jīng)常會(huì)碰到這樣的問(wèn)題。在Linux系統(tǒng)中,強(qiáng)大的shell就可以很靈活的處理這樣的事務(wù)2013-06-06
數(shù)據(jù)結(jié)構(gòu) 二叉樹(shù)的遞歸與非遞歸
這篇文章主要介紹了數(shù)據(jù)結(jié)構(gòu) 二叉樹(shù)的遞歸與非遞歸的相關(guān)資料,需要的朋友可以參考下2017-05-05
Linux SHELL if命令參數(shù)說(shuō)明
SHELL if命令參數(shù)介紹,方便學(xué)習(xí)shell命令的朋友,需要的朋友可以參考下2013-01-01

