当大量文件(> 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文件计数
发布评论