Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can /tmp in Linux ever fill up?

Tags:

linux

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

like image 926
Thomas Kessler Avatar asked Feb 11 '09 15:02

Thomas Kessler


People also ask

What will happen if tmp is full in Linux?

If a user decides to dump a huge amount of data into the /tmp directory, this action can cause other problems, such as not being able to log into the system via SSH. Maintaining the /tmp directory isn't easy. Users love to dump files into /tmp and leave them there indefinitely.

What happens if tmp fills?

If someone fills /tmp then the OS can't swap and that may not cause real problems but usually means no more processes (including login) can be started. We normally run a cron job that removes older files from /tmp to minimise this.

How often is tmp emptied?

By default files in /tmp/ are cleaned up after 10 days, and those in /var/tmp after 30 days.

How long do TMP files last Linux?

By default, all the files and data that gets stored in /var/tmp live for up to 30 days. Whereas in /tmp, the data gets automatically deleted after ten days. Furthermore, any temporary files that are stored in the /tmp directory get removed immediately on system reboot.


2 Answers

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.

like image 82
Ori Pessach Avatar answered Sep 21 '22 13:09

Ori Pessach


The only thing you can write to without worrying it will fill up is /dev/null. Everything else will eventually run out of space if you keep dumping things in it.

One simple approach would be to have a cron job clean up all your /tmp files that are older than, say, a few days.

like image 28
Tiberiu Ana Avatar answered Sep 20 '22 13:09

Tiberiu Ana