1. Home
  2. Linux

How to increase the size of the temp folder on Linux

Are you doing something on your Linux PC that has lead to your temporary directory filling up to 100%? Frustrated that it is filled and wish there was more space to work with. If so, this guide is for you! Follow along as we show you how to increase the size of the temp folder on Linux!

Option 1 – One time remount for a temporary increase in size

If you don’t run out of space in the /tmp directory often, it doesn’t make sense to increase the size permanently. Instead, it’s better to have a command handy that you can execute on the rare occasion that your /tmp directory runs out of space. 

To temporarily increase the size of the /tmp directory, you will need to unmount the folder while it is in use and use a special command to remount it while specifying how large you want the folder to be.

Keep in mind that this command is temporary and only lasts so long as your computer is logged in. The minute you reboot your system, your /tmp folder will go back to its default size, which is adequate for most users.

To temporarily change the size of the /tmp directory, follow the step-by-step instructions below.

Step 1: Open up a terminal window. Sadly, no deep system-level modification on Linux is possible without a terminal window. Once a terminal window is open, use the sudo -s command to give the terminal window root access.

sudo -s

Step 2: After logging into the root directory, you must use the df command with the command switch to determine if your /tmp folder has reached 100% usage. Using the command below, determine if the /tmp folder is 100% full.

df -h /tmp

If it is filled, you will see 100% under the “Use%” column.

Step 3: It is time to remount the /tmp directory with a new, larger size. For this example, we will give the /tmp directory 5 GiBs of space to work with. This size limit should be more than enough. However, feel free to change it to suit your needs.

mount -o remount,size=5G /tmp/

Step 4: With the /tmp directory dismounted and remounted with a new, larger size, your /tmp directory should no longer be filled up. To confirm this, execute the df command with the command switch.

df -h /tmp

You should see the “Use%” column no longer reading 100%, indicating that you have more space in your /tmp directory to work with. Enjoy!

Terminal command to resize the temporary directory easily at any time

If you’d like to make it easier to access the temporary resize command, you can add it as an alias to your .bashrc file. Follow the step-by-step instructions below to set up the alias.

Step 1: Open up a terminal window. Then, use the cp command to make a quick backup of your existing .bashrc file. This backup will allow you to remove the changes made here quickly.

cp ~/.bashrc ~/bashrc-backup

Step 2: Open up the .bashrc file for editing in the Nano text editor. Please do not use the sudo command, or it will open up the root .bashrc file and not your users’ one!

nano -w ~/.bashrc

Step 3: Paste the following code at the end of the file. Be sure that this code is exactly as it appears in the example below or will not work.

alias expand-temp='sudo mount -o remount,size=5G /tmp/'

Step 4: Press Ctrl + O on the keyboard to save your changes. Then, close the terminal you’re using and open up a new one.

Step 5: Execute expand-temp in a terminal window to remount your /tmp directory with a larger size.


Option 2 – Permanently resize the temp directory

If having a permanently larger /tmp directory is important to you, you can go into the /etc/fstab settings and modify it so that you have more space to work with. Here’s how to do it.

Warning: we do not recommend permanently modifying your /tmp directory unless you are an advanced Linux user and understand how the system works. This kind of modification is tricky, and you could cause problems with your Linux installation!

To change the size of /tmp permanently, follow the step-by-step instructions below.

Step 1: Open up a terminal window and elevate its permissions to the root user using sudo -s.

sudo -s

Step 2: Open up the /etc/fstab file in the Nano text editor for editing purposes.

nano -w /etc/fstab

Step 3: Paste the following code below at the very bottom of the /etc/fstab file. The code must look exactly as it does in the example, or it will break!

#Temporary folder TMPFS

tmpfs /tmp tmpfs rw,nodev,nosuid,size=5G 0 0

Step 4: Save the edits to the /etc/fstab file by pressing the Ctrl + O button on the keyboard. Then, exit Nano using Ctrl + X.

Step 5: Reboot your Linux PC. When you log back in, your /tmp directory should be much larger.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.