restore tmp directory in linux

How to Restore Deleted Tmp Directory in Linux

Every system has a /tmp directory that is used for temporary storage of files and data. It is generally used by applications and scripts to create lock files, temporary storage of data, files required to run the program currently and delete later on when program is closed. Its contents are automatically deleted when you boot or shutdown your Linux system, as a part of system administration. However, if you delete these files when your program is running, it may crash your program. So you have to be very careful before deleting this /tmp folder. If you have multiple users working on your system, it can even disturb their activities and sessions. However, if you or someone else accidentally deletes this directory, you will need to restore it quickly. In this article, we will learn how to restore deleted tmp directory in Linux.

How to Restore Deleted Tmp Directory in Linux

Before we proceed, you need to ensure that the /tmp directory must belong to the root user, and you should modify the permissions of this directory such that all users are able to access it.

For this purpose, you can run the following commands.

$ sudo mkdir /tmp 
$ sudo chmod 1777 /tmp
$ sudo mkdir -m 1777 /tmp

In the above command we use the permission 1777 to specify that every body (owner, group and others) can access its contents but only owner can delete it. This is done using the sticky bit ‘t’ by settings its value as 1.

Run the following command to check its permissions.

$ ls -ld /tmp

Once you have restored /tmp directory you can reboot the system to ensure that all programs work properly. In this article, we have learnt how to restore the /tmp directory by recreating it and settings it sticky bit.

Also read:

How to Change Linux Partition Label Names
How to Disable Output Buffering in Python
How to Read Large Files in Python
How to Copy File Permission & Ownership in Linux
Display Command Output & File Content in Column Format

Leave a Reply

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