10

Accidently, I ran sudo rm -r /tmp, is that a problem ?
I recreated it using sudo mkdir /tmp, does that fix the problem ?

After I recreated the directory, In the places section in the sidebar in nautilus in Ubuntu 14.04 I can see /tmp , which wasn't there before .. Is that a problem ?

One last thing, do I have to run sudo chown $USER:$USER /tmp to make it accessible as it was before .. Would there be any side-effects after this ?

By the way, I get this seemingly-related error whenI try to use bash autocompletion

bash: cannot create temp file for here-document: Permission denied

2 Answers 2

15

/tmp can be considered as a typical directory in most cases. You can recreate it, give it to root (chown root:root /tmp) and set 1777 permissions on it so that everyone can use it (chmod 1777 /tmp). This operation will be even more important if your /tmp is on a separate partition (which makes it a mount point).

By the way, since many programs rely on temporary files, I would recommend a reboot to ensure that all programs resume as usual. Even if most programs are designed to handle these situations properly, some may not.

3
  • 2
    /tmp doesn't need to have a partition, though it can be. /tmp can also be a filesystem of type tmpfs or ramfs keeping tmp files in memory. One needs to decide between ram or device depending on use, size of data, etc. Commented Aug 12, 2014 at 17:06
  • The final info is: drwxrwxrwt 5 root root 4096 أغس 12 20:21 tmp/ .. Is that fine ? Commented Aug 12, 2014 at 17:23
  • @AmrAyman These are typical /tmp permissions, yes. rwx everywhere so that everyone can read and write to it, and a sticky bit (t) to ensure individual files ownership/permissions inside /tmp. See here for more info. Commented Aug 12, 2014 at 17:26
5

The directory /tmp must have the permissions 1777 = rwxrwxrwt, i.e. everybody can read, write and access files in the directory, and (t = sticky bit) files may only be deleted by their owner. A lot of things will stop working if this isn't the case, sometimes in bizarre ways.

sudo mkdir -m 1777 /tmp 

or

sudo mkdir /tmp && sudo chmod 1777 /tmp 

/tmp must belong to root. Don't change its ownership to another user.

Programs that were using temporary files at the time you deleted them may be a bit confused. A few background programs keep a socket in /tmp and will need to be restarted. The main one is the X server: after deleting /tmp/.X11-unix/X0, you will no longer be able to start any GUI application. You'll need to log out and back in to remedy that (fix the permissions first!).

1
  • is it not chmod? Commented Aug 13, 2014 at 0:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.