Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajesh-gonuguntla/162b9ef3e92babebb4b5 to your computer and use it in GitHub Desktop.
Save rajesh-gonuguntla/162b9ef3e92babebb4b5 to your computer and use it in GitHub Desktop.
How to clear tmp folder every x seconds or minutes
// Step 1 Install tmpreaper
sudo apt-get install tmpreaper
/**
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.
*/
// Create a shell script which executes tmpreaper
Create bash script (tmpcleaner.sh):
#!/bin/bash
tmpreaper --all --protect .localized 2s /tmp/
// Step 3 Add executable permission on the script
chmod +x tmpcleaner.sh
// Step 4 Make it a cron job
crontab -e
Add to the crontab(add the variable PATH where is located tmpreaper):
PATH=/usr/sbin:/usr/bin:/sbin:/bin
* * * * * /tmpcleaner.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment