Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a more beautiful way to check /tmp and /var/tmp is clean (= files that haven't been accessed in 72 hours are being automatically deleted). I think of running the following script as daily cron job:
Code:
#!/bin/sh
# clean up /tmp and /var/tmp
if [ -d /tmp -a -r /var/tmp ]
then
find /tmp -type f -atime +3 -exec rm {} \;
find /var/tmp -type f -atime +3 -exec rm {} \;
fi
It is a little paranoid checking to see if /tmp is a directory and that the user has read permission to /var/tmp, but otherwise it will work.
The only other comment I have is that atime returns an integer and +3 means greater than 3 days which does not happen till 4 days or 96 hours (as 3.5 days access would truncate to 3 which is not greater than 3). But a 24 hour grace period shouldn't hurt. At least that is how is has always appeared to be implemented on my system.
Originally posted by LJSBrokken I hate to wake up old threads, but since this little script was exactly what I was looking for I post my question here anyway.
Is there a reason not to include some lines to also remove directories that are found in /tmp or /var/tmp?
Cheers, Leon.
Not really, just preferences really. I just have scripts on bootup to clean out all files in /tmp... I don't like to clean out this directory while the system is running, could accidently wipe out files that are in use
Only if a directory is empty and been unmodified for more than 99 days will it be removed.
My time is probably a bit excessive, it takes years to remove an entire build tree I may through in tmp because I don't think I need it but not quite ready to "rm -rf" it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.