What is the sticky bit in UNIX file systems? When is it used?

18,279

Solution 1

Its original use was to provide a hint to the OS that the executable should be cached in memory so it would load faster. This use has mostly been deprecated as OSes are pretty smart about this sort of thing now. In fact, I think now some OSes use it as a hint that the executable shouldn’t be cached.

The most common use today is to create a directory in which anyone can create a file, but only the owner of a file in that directory can delete it. Traditionally, if you have a directory that anyone can write to, anyone can also delete a file from it. setting the sticky bit on a directory makes it so only the owner of a file can delete the file from a world-writeable directory.

The classic use of this is the /tmp directory:

$ ls -ld /tmp
drwxrwxrwt   29 root     root         5120 May 20 09:15 /tmp/

The t in the mode there is the sticky bit. If that wasn’t set, it would be pretty easy for a regular user to cause havoc by deleting everything from /tmp. Since lots of daemons put sockets in /tmp, it would essentially be a local DOS.

Solution 2

http://en.wikipedia.org/wiki/Sticky_bit

Share:
18,279

Related videos on Youtube

Aaron K
Author by

Aaron K

Currently working as a combo sysadmin, dev, and PM. Most dev work is on the web stack using PHP (with Cake) and dabbling in Rails. Striving for the one app to rule them [nodes] all...

Updated on September 17, 2022

Comments

  • Aaron K
    Aaron K over 1 year

    What is the sticky bit in a UNIX file system?

    As an admin when and how would you use it?

  • Chris Wesseling
    Chris Wesseling almost 11 years
    Normally I'm not a fan of single URL answers. But this wikipedia page is exceptionally complete; it contains a nice table of behaviours across *nix systems.
  • Pacerier
    Pacerier over 6 years
    "hint that the executable shouldn’t be cached"????