Hello Alireza,
Hope you are doing well today! To change the /tmp directory in Linux to a different path, you can follow these steps:
- Create a new directory that will be used as the new temporary directory. For example,
mkdir /newtmp
. - Change the ownership and permissions of the new directory so that it is usable as a temporary directory. For example,
chown root:root /newtmp
andchmod 1777 /newtmp
. - Modify the
/etc/fstab
file to mount the new temporary directory as/tmp
at boot time. For example, add the line/newtmp /tmp none bind 0 0
to the file. - Unmount the current
/tmp
directory. For example,umount /tmp
. - Mount the new
/tmp
directory. For example,mount /tmp
. - Verify that the change was successful by checking the content of the
/tmp
directory. For example,ls -la /tmp
.
Please make sure I assume that you have root access to the system. Before making any changes to the /etc/fstab
file, make sure to backup the file to prevent any data loss.
Regards,
Umang Middha