LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How can I clean /tmp while system is running? (https://www.linuxquestions.org/questions/linux-general-1/how-can-i-clean-tmp-while-system-is-running-4175574713/)

ahc_fan 03-12-2016 07:20 PM

How can I clean /tmp while system is running?
 
I know I can put a command in the shutdown script to clean /tmp, but I rarely reboot my computer. So how should I manage this? Do I use cron and periodically delete files that are certain age? Could someone provide examples? Thank you.

cliffordw 03-13-2016 11:28 AM

Hi there,

Yes, a daily cron job should do the trick nicely. Possibly something like this:

Code:

find /tmp -xdev -type f -atime +1 -print | xargs rm

Habitual 03-17-2016 05:25 PM

Back when I ran Slackware (14'ish), I installed tmpwatch.
Seemed to do the job.

Now-a-days, I guess the new fangled thing is to mount /tmp as tmpfs file system and it gets
emptied on every reboot?

sundialsvcs 03-17-2016 09:30 PM

Not too familiar with tmpfs, but a Linux machine might well not be 'rebooted' for months at a time . . .

kohli 03-18-2016 12:59 AM

The tmpreaper program can be used to clean up /tmp periodically. This program deletes everything that has not been accessed in a given timeframe, typically two weeks. For this to work properly, the filesystem it is on should have the atimes option enabled. If you use a tmpfs, which it appears you are doing, then you should be fine.

Of course, rebooting also clears /tmp, but that would be boring.


All times are GMT -5. The time now is 07:16 AM.