Ubuntu – the “t” letter in the output of “ls -ld /tmp”


When running the command ls -ld /tmp, the output would be:

drwxrwxrwt 30 root root 20480 Mar 11 14:17 /tmp

So I have two main questions:

  • What is the letter t after the permissions?
  • As far as I know /tmp is used to create temporary files related to
    different users in the system, so how come it has permission rwxrwxrwx (777)?

This seems wrong for me. Please I need your help to understand what is going here.

Best Answer

So what is the sticky bit?

A sticky bit is a permission bit that is set on a directory that allows only the owner of the file within that directory, the owner of the directory or the root user to delete or rename the file. No other user has the needed privileges to delete the file created by some other user.

This is a security measure to avoid deletion of critical folders and their content (sub-directories and files), though other users have full permissions.

Why does /tmp have the t sticky bit?

The /tmp directory can be used by different Linux users to create temporary files. Now, what if an user deletes/rename a file created by some other user in this directory?

Well, to avoid these kind of issues, the concept of sticky bit is used. So for that a 777 is given but preserving the sticky bit is not a bad idea.

How can I setup the sticky bit for a directory?

I'll set a sticky bit on a directory called test on my Desktop.

Symbolic way (t represents the sticky bit):

chmod o+t ~/Desktop/test


chmod +t ~/Desktop/test

Numerical/octal way (1, sticky bit bit as value 1 in the first position)

chmod 1757 ~/Desktop/test

Now let us test the results:

ls -li ~/Desktop/test

1551793 drwxrwxrwt 45 hadi hadi 20485 Mar 11 14:35 ~/Desktop/test

To delete/Remove a sticky bit

chmod o-t ~/Desktop/test

Now let us test the results:

ls -li ~/Desktop/test

1551793 drwxrwxrwx 45 hadi hadi 20485 Mar 11 14:35 ~/Desktop/test

Source: “What is a sticky Bit and how to set it in Linux?” at The Linux Juggernaut

Related Question