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.
ls -R -al --time-style=+%D /tmp | grep `date +%D`|wc -l
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.