[英]How to quickly count files/folders in a directory by age?
I'm trying to get a count of all files or folders older than 1 day in /tmp with:我正在尝试计算 /tmp 中超过 1 天的所有文件或文件夹的计数:
find /tmp/* -ctime +1 | wc -l
This takes 30 minutes to run.这需要运行 30 分钟。 However,
ls /tmp | wc -l
但是,
ls /tmp | wc -l
ls /tmp | wc -l
runs in a second and shows there's only about 50,000 files. ls /tmp | wc -l
运行一秒钟,显示只有大约 50,000 个文件。
Why is find
so slow?为什么
find
这么慢? How do I speed it up?我该如何加快速度?
Edit: You can simulate this situation yourself by running:编辑:您可以通过运行自己模拟这种情况:
python -c "import tempfile, os; [os.close(tempfile.mkstemp()[0]) for i in range(50000)]"
and then running my find
command.然后运行我的
find
命令。
ls -R -al --time-style=+%D /tmp | grep `date +%D`|wc -l
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.