How to Restore Deleted /tmp Directory in Linux

The /tmp directory contains mostly files that are required temporarily, it is used by different programs to create lock files and for temporary storage of data. Many of these files are important for currently running programs and deleting them may result in a system crash.

On all if not most Linux systems, the contents of the /tmp directory are deleted (cleared out) at boot time or at shutdown by the local system. This is a standard procedure for system administration, to reduce the amount of storage space used (typically, on a disk drive).

Important: Do not delete files from the /tmp directory unless you know exactly what you are doing! In multi-user systems, this can potentially remove active files, disrupting users activities (via programs they are using).

What if you accidentally delete the /tmp directory? In this article, we will show you how to restore (recreate) /tmp directory after deleting it.

Suggested Read: How to Recover Deleted Files in Linux

A few things to note before running the commands below.

  • the /tmp must belong to the root user.
  • set appropriate permissions that will allow all users to use this directory (make it public).
$ sudo mkdir /tmp 
$ sudo chmod 1777 /tmp

Alternatively, run this command.

$ sudo mkdir -m 1777 /tmp

Now run the command below to check the permissions of the directory.

$ ls -ld /tmp
Restore Deleted /tmp Directory in Linux
Restore Deleted /tmp Directory in Linux

The permission set here mean everybody (owner, group and others) can read, write and access files in the directory, and the t (sticky bit), implying files may only be deleted by their owner.

Note: Once you have restored the /tmp directory as shown above, it is recommended you reboot the system to ensure that all programs start operating normally.

That’s it! In this article, we showed how to restore (recreate) /tmp directory after deleting it accidentally in Linux. Drop your comments via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

10 Comments

Leave a Reply
      • /tmp/fluxspace/client.txt files and /tmp/fluxspace/hit.txt files are missing in my Linux . Though I’m not able to perform an evil twin attack. I’m using Debian Linux as a live OS. Please help. TAKE IT AS A CHALLENGE. Please help

        Reply
  1. AWESOME information!….This will definitely come in handy for me…..since I’m constantly installing / removing Linux distros, and sometimes I make that mistake of deleting the wrong thing! Thanks for such a great, informative article!!

    Reply
    • @Eddie

      Welcome, it’s simple and direct, but informative as we always like to keep it. Many thanks for always following us.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.