/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.
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
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.