简体   繁体   中英

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:

find /tmp/* -ctime +1 | wc -l

This takes 30 minutes to run. However, ls /tmp | wc -l ls /tmp | wc -l runs in a second and shows there's only about 50,000 files.

Why is find so slow? 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.

List today files via ls and count files/folders inside tmp folder:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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