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
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.
Thank you!!! fixed it right away perfectly. useful article :-) !
Thanks man, I am able to recover my deleted
/tmp
directory with your instructions..@Lior
Welcome, many thanks for the feedback.
‘Restore’ and ‘recreate’ are two absolutely different things……
@justsaying
Yes, practically, they are different things altogether, we will update article soon.
/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
Hi,
Thanks a lot….
@Jalal
Welcome, thanks too for always following us.
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!!
@Eddie
Welcome, it’s simple and direct, but informative as we always like to keep it. Many thanks for always following us.