>  기사  >  운영 및 유지보수  >  Linux에서 파일을 삭제하는 6가지 방법(요약)

Linux에서 파일을 삭제하는 6가지 방법(요약)

ringa_lee
ringa_lee원래의
2017-06-23 11:46:334538검색

먼저 500,000개의 파일을 생성하세요:

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.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 &#39;for(<*>){((stat)[9]<(unlink))}&#39;
perl -e &#39;for(<*>){((stat)[9]<(unlink))}&#39;  1.28s user 7.23s system 50% cpu 16.784 total


위 내용은 Linux에서 파일을 삭제하는 6가지 방법(요약)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.