大量文件的快速Linux文件计数 [英] Fast Linux File Count for a large number of files
问题描述
当大量文件(> 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文件计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!