Skip to content
Advertisement

Can /tmp in Linux ever fill up?

I’m putting some files in /tmp on a web server that are being used by a web application for a limited amount of time. If the files get left in the server’s /tmp after the user quits using the application and this happens repeatedly, should i be concerned about the directory filling up? I read online that rebooting cleans out the /tmp directory, but this box doesn’t get rebooted very much.

Tom

Advertisement

Answer

Yes, it will fill up. Consider implementing a cron job that will delete old files after a while.

Something like this should do the trick:

/usr/bin/find /tmp/mydata -type f -atime +1 -exec rm -f {} ;

This will delete files that have a modification time that’s more than a day old.

Or as a crontab entry:

   # run five minutes after midnight, every day
   5 0 * * *       /usr/bin/find /tmp/mydata -type f -atime +1 -exec rm -f {} ;

where /tmp/mydata is a subdirectory where your application stores its temporary files. (Simply deleting old files under /tmp would be a very bad idea, as someone else pointed out here.)

Look at the crontab and find man pages for the details. Don’t go running scripts that delete files on your filesystem without understanding all the details – that’s how bad things happen to good servers. 🙂

Of course, if you can just modify your application to delete temporary files when it’s done with them, that would be a far better solution, generally.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement