linux删除文件的6种方法(总结)
首先建立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中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

Linux终端中查看Python版本时遇到权限问题的解决方法当你在Linux终端中尝试查看Python的版本时,输入python...

在Docker环境中使用PECL安装扩展时报错的原因及解决方法在使用Docker环境时,我们常常会遇到一些令人头疼的问�...

在LAMP架构下整合Node.js或Python服务许多网站开发者都面临这样的问题:已有的LAMP(Linux Apache MySQL PHP)架构网站需要...

在macOS上将apscheduler定时任务配置为服务在macOS平台上,如果你想将apscheduler定时任务配置为一个服务,类似于ngin...

语言多线程可以大大提升程序效率,C 语言中多线程的实现方式主要有四种:创建独立进程:创建多个独立运行的进程,每个进程拥有自己的内存空间。伪多线程:在一个进程中创建多个执行流,这些执行流共享同一内存空间,并交替执行。多线程库:使用pthreads等多线程库创建和管理线程,提供了丰富的线程操作函数。协程:一种轻量级的多线程实现,将任务划分成小的子任务,轮流执行。

关于Linux系统自带Python解释器的删除问题许多Linux发行版在安装时会预装Python解释器,它并非通过软件包管理器�...

要打开 web.xml 文件,可以使用以下方法:使用文本编辑器(如记事本或 TextEdit)使用集成开发环境(如 Eclipse 或 NetBeans)使用命令行编辑命令(Windows:notepad web.xml;Mac/Linux:open -a TextEdit web.xml)
