简体   繁体   English

如何按年龄快速计算目录中的文件/文件夹?

[英]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命令。

List today files via ls and count files/folders inside tmp folder:通过 ls 列出今天的文件并计算 tmp 文件夹中的文件/文件夹:

Example:例子:

ls -R -al --time-style=+%D /tmp | grep `date +%D`|wc -l

This will list today files only as you asking for, change date after your needs.这将仅根据您的要求列出今天的文件,根据您的需要更改日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM