The most efficient way to delete old files with bash

I execute this command every 30 minutes through a bash script (on Centos 6) to delete files that are about 1 hour old. The problem is that the team finduses 45% of my cpu at all times. Is there any way to optimize it. At any given time in the cache there will be about 200 thousand elements.

find /dev/shm/cache -type f -mmin +59 -exec rm -f {} \;
+4
source share
2 answers

You can try to start the process as a lower priority using nice:

nice -n 19 find ...

, , find, -delete -exec:

find /dev/shm/cache -type f -mmin +59 -delete

... , find ( @chepner ) ( ...)

+5

rm , . , rm, , OS. + ;

find /dev/shm/cache -type f -mmin +59 -exec rm -f {} +

-delete, janos; , . , , , .

-exec grep foo {} +
+2

Source: https://habr.com/ru/post/1613553/


All Articles