The sticky bit was introduced in the Fifth Edition of Unix (in 1974) for use with pure executable files.2 When set, it instructed the operating system to retain the text segment of the program in swap space after the process exited. This speeds up subsequent executions by allowing the kernel to make a single operation of moving the program from swap to real memory. Thus, frequently-used programs like editors would load noticeably faster. One notable problem with "stickied" programs was replacing the executable (for instance, during patching); to do so required removing the sticky bit from the executable, executing the program and exiting to flush the cache, replacing the binary executable, and then restoring the sticky bit.
Subsequently, this behavior became operative only in HP-UX and UnixWare. Solaris appears to have abandoned this in 2005. The 4.4-Lite release of BSD retained the old sticky bit behavior, but it has been subsequently dropped from OpenBSD (as of release 3.7) and FreeBSD (as of release 2.2.1). No version of Linux has ever supported this traditional behavior; Linux performs caching of executable files in the same way as all files, so re-executing the program to flush the cache is not necessary.
The most common modern use of the sticky bit is on directories residing within filesystems for Unix-like operating systems. When a directory's sticky bit is set, the filesystem treats the files in such directories in a special way so only the file's owner, the directory's owner, or root can rename or delete the file. Without the sticky bit set, any user with write and execute permissions for the directory can rename or delete contained files, regardless of the file's owner. Typically, this is set on the /tmp directory to prevent ordinary users from deleting or moving other users' files. This feature was introduced in 4.3BSD in 1986, and today it is found in most modern Unix-like systems.
In addition, Solaris (as of Solaris 2.5) defines special behavior when the sticky bit is set on non-executable files: those files, when accessed, will not be cached by the kernel. This is usually set on swap files to prevent access on the file from flushing more important data from the system cache. It is also used occasionally for benchmarking tests.
The sticky bit is also set by the automounter to indicate that a file has not been mounted yet. This allows programs like ls to ignore unmounted remote files.
Any user may create a sticky directory. See chmod(1) for details about modifying file modes.
Only the superuser can set the sticky bit on a file, though the owner of the file may clear the sticky bit.
The sticky bit can be set using the chmod command and can be set using its octal mode 1000 or by its symbol t (s is already used by the setuid bit). For example, to add the bit on the directory /usr/local/tmp, one would type chmod +t /usr/local/tmp. Or, to make sure that directory has standard tmp permissions, one could also type chmod 1777 /usr/local/tmp.
To clear it, use chmod -t /usr/local/tmp or chmod 0777 /usr/local/tmp (the latter will also reset the tmp directory to standard permissions).
In Unix symbolic file system permission notation, the sticky bit is represented either by the letter t or T in the final character-place depending on whether the execution bit for the others category is set or unset, respectively. For instance, on Solaris 8, the /tmp directory, which by default has both the others execute bit and the sticky-bit set, shows up as:
If the sticky-bit is set on a file or directory without the execution bit set for the others category (non-user-owner and non-group-owner), it is indicated with a capital T (replacing what would otherwise be -):
Zintz, Walter (February 1984). "The Unix Connection: What is a sticky bit?". HARDCOPY. p. 130. /wiki/HARDCOPY ↩
Steinhauser, Martin Oliver (2012). Computer Simulation in Physics and Engineering. De Gruyter. ISBN 978-3-1102-5590-4. 978-3-1102-5590-4 ↩
"Archived copy of chmod man page under AIX 5.2". Archived from the original on 2005-01-18. Retrieved 2009-01-19. https://archive.today/20050118170142/http://moka.ccr.jussieu.fr/doc_link/en_US/a_doc_lib/cmds/aixcmds1/chmod.htm ↩
"Synopsis - man pages section 2: System Calls". Docs.oracle.com. 2011-11-01. Retrieved 2014-04-10. http://docs.oracle.com/cd/E23824_01/html/821-1463/chmod-2.html#REFMAN2chmod-2 ↩
"HPUX chmod[2]". Archived from the original on November 20, 2007. Retrieved February 29, 2008.{{cite web}}: CS1 maint: bot: original URL status unknown (link) https://web.archive.org/web/20071120004625/http://www.informatik.uni-frankfurt.de/doc/man/hpux/chmod.2.html ↩
"chmod(1) - Linux manual page". Man7.org. Retrieved 2014-04-10. http://man7.org/linux/man-pages/man1/chmod.1.html ↩
"proc(5) - Linux manual page". Man7.org. Retrieved 2022-03-04. https://man7.org/linux/man-pages/man5/proc.5.html#:~:text=/proc/sys/fs/protected_fifos ↩
"chmod - FreeBSD". Nixdoc.net. 1993-06-04. Retrieved 2014-04-10. http://nixdoc.net/man-pages/FreeBSD/man2/chmod.2.html ↩
"chmod - IRIX/standard/". Nixdoc.net. Retrieved 2014-04-10. http://nixdoc.net/man-pages/IRIX/man2/standard/chmod.2.html ↩
"Mac Developer Library". Developer.apple.com. Retrieved 2014-04-10. https://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man8/sticky.8.html ↩
"sticky.7 - NetBSD Manual Pages". Netbsd.gw.com. 2021-05-16. Retrieved 2021-05-16. http://man.netbsd.org/sticky.7 ↩
"Manual Pages: sticky". Openbsd.org. 2014-02-14. Retrieved 2018-02-04. https://man.openbsd.org/sticky.8 ↩
"chmod(2)". Uw714doc.sco.com. 2004-04-25. Retrieved 2014-04-10. http://uw714doc.sco.com/en/man/html.2/chmod.2.html ↩