0

I have the following cron setup to clear the tmp folder:

0 0 * * *  rm -rf /home/user/tmp/* >> /dev/null 2>&1

However I'm looking for a more efficient way which would be less CPU intensive as this would have to clear 1000+ files daily.

How can I edit this to make it less CPU intensive?

Oudin
  • 331
  • 2
  • 5
  • 10
  • 1
    You may find some useful information at one of our sister sites: http://unix.stackexchange.com/q/37329/4772 – Mark Henderson Nov 14 '16 at 18:00
  • I'm not including this as an answer since I have never tried it, I wonder if setting the nice value to 19 would help. – Charles Burge Nov 14 '16 at 23:52
  • Setting nice would help it stay out fo the way of other running jobs, but it wouldn't make it more CPU efficient on its own. Maybe that's all @Oudin wants. Speaking of, Oudin, what exactly is the issue here? Is this job slowing things down on a single system, or are you simply looking for a more efficient process? – Spooler Nov 15 '16 at 01:59
  • @SmallLoanOf1M I'm just looking for a more efficient process. "find . -type f -delete" works however I tried setting a cron as "0 0 * * * find . -type f -delete /home/user/tmp/* >> /dev/null 2>&1" and it did not work. Is there anything wrong/missing? – Oudin Nov 15 '16 at 15:48

1 Answers1

2

You could use a small dedicated filesystem mounted to that directory. When you want to clear it, you can unmount it, reformat it with the same label, and then remount it by label. That would certainly be much more CPU efficient than clearing out what I'm assuming are a bunch of small files.

Spooler
  • 7,016
  • 16
  • 29