Linux – How long do uploaded files stay in the tmp folder in Linux Ubuntu

hard drivelinuxtmpUbuntuupload

I am building a web application where my users will be able to upload files. After the files are uploaded I need to send the files to two other servers, and after they will be deleted from the server where they were just uploaded to.

I am wandering is it a good I idea to keep the uploaded files in the tmp/ folder the time the uploaded files are sent to the other two servers or should I move them to another folder incase they get deleted? I am also wandering because I would like to know if I have to build a cron script to get rid of the files that have been transfered to the other servers so that I get my disk space back.

Best Answer

By default the tmp directory is cleaned up at every (re)boot. You can set the live time in days by increasing TMPTIME in the following file: /etc/default/rcS.

I'm not aware of any automatically clean up process for temp directory during runtime. But it should be possible with a little script which is called by cron and deletes older files. Note do not delete files in the tmp directory you are not aware of - the best would be to save your uploads within a separate directory in tmp.