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

8,513

Solution 1

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.

Solution 2

You should at least be aware of the settings for the folder.

Here is a default /etc/rcS file.

 $: cat /etc/default/rcS                                                     
#                                                                            
# /etc/default/rcS                                                           
#                                                                            
# Default settings for the scripts in /etc/rcS.d/                            
#                                                                            
# For information about these variables see the rcS(5) manual page.          
#                                                                            
# This file belongs to the "initscripts" package.                            

# delete files in /tmp during boot older than x days.                        
# '0' means always, -1 or 'infinite' disables the feature                    
TMPTIME=0                                                                    

# spawn sulogin during boot, continue normal boot if not used in 30 seconds  
SULOGIN=no                                                                   

# do not allow users to log in until the boot has completed                  
DELAYLOGIN=no                                                                

# assume that the BIOS clock is set to UTC time (recommended)                
UTC=yes                                                                      

# be more verbose during the boot process                                    
VERBOSE=no                                                                   

# automatically repair filesystems with inconsistencies during boot          
FSCKFIX=no                                                                   

So basically, you can have the rough grain control here for when to delete, and a finer control if you were to setup a cron job as you are suggesting. Perhaps certain kinds of files get deleted sooner in your cron job than the setting here, for example.

Share:
8,513
jnbdz
Author by

jnbdz

Updated on September 18, 2022

Comments

  • jnbdz
    jnbdz almost 2 years

    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.

    • Ladadadada
      Ladadadada over 11 years
      I have a colleague who likes to put log files in /tmp/. Some of them have been there for years.
    • Michael Hampton
      Michael Hampton over 11 years
      @Ladadadada One of these days, your colleague is in for a very unpleasant surprise.
    • jnbdz
      jnbdz over 11 years
      ^lol! You are funny.