Wednesday, May 8, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  14] [ 0]  / answers: 1 / hits: 14035  / 2 Years ago, fri, november 4, 2022, 2:56:00

Is it safe to use a bash script and a cronjob to empty /tmp automatically, or should I do this differently?


More From » cron

 Answers
5

/tmp is cleaned on every system reboot, but for systems that cannot be rebooted often, and specially if the only objective is to clean /tmp a script can be made to clean it.



No process should keep important data there but it is important that you are able to clean /tmp without disrupting any processes writing data in tmp.



I recommend to use tmpreaper for that.



You can install it with sudo apt-get install tmpreaper.



From the man page:




tmpreaper recursively searches for and removes files and empty directories which haven't been accessed for a given number of seconds. Normally, it's used to clean up directories which are used for temporary holding space, such as "/tmp". Please read the WARNINGS section of this manual.




Usage normally involves invoking tmpreaper in /tmp with a time spec argument. The time spec argument can be anything from d for days, h for hours, m for minutes, or s for seconds.



Please use the --test to dry run and get an output of the results before you actually run the command. That will get you an idea of what will be deleted before you actually commit any changes to the file system.


[#26634] Friday, November 4, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diket

Total Points: 167
Total Questions: 124
Total Answers: 109

Location: Somalia
Member since Wed, Mar 15, 2023
1 Year ago
;