大量文件的快速Linux文件计数

编程入门 行业动态 更新时间:2024-10-23 21:35:45
本文介绍了大量文件的快速Linux文件计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当大量文件(> 100,000)时,我试图找出在特定目录中查找文件数的最佳方法.

I'm trying to figure out the best way to find the number of files in a particular directory when there are a very large number of files ( > 100,000).

当文件太多时,执行ls | wc -l会花费很长的时间.我相信这是因为它正在返回所有文件的名称.我正在尝试占用尽可能少的磁盘IO.

When there are that many files, performing ls | wc -l takes quite a long time to execute. I believe this is because it's returning the names of all the files. I'm trying to take up as little of the disk IO as possible.

我尝试了一些shell和Perl脚本,但无济于事.有什么想法吗?

I have experimented with some shell and Perl scripts to no avail. Any ideas?

推荐答案

默认情况下,ls对名称进行排序,如果名称很多,则可能需要一段时间.在所有名称被读取和排序之前,也不会有输出.使用ls -f选项关闭排序.

By default ls sorts the names, which can take a while if there are a lot of them. Also there will be no output until all of the names are read and sorted. Use the ls -f option to turn off sorting.

ls -f | wc -l

请注意,这还将启用-a,因此将计算.,..和其他以.开头的文件.

Note that this will also enable -a, so ., .., and other files starting with . will be counted.

更多推荐

大量文件的快速Linux文件计数

本文发布于:2023-11-11 06:21:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   快速   Linux

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!