In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
, the sticky bit is a user ownership
access right flag
A flag is a piece of textile, fabric (most often rectangular) with distinctive colours and design. It is used as a symbol, a signalling device, or for decoration. The term ''flag'' is also used to refer to the graphic design employed, and fla ...
that can be assigned to
files and
directories on
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
systems.
There are two definitions: one for files, and one for directories.
For files, particularly executables, the superuser could tag these as to be retained in main memory, even when their need ends, to minimize swapping that would occur when another need arises, and the file now has to be reloaded from relatively slow secondary memory. This function has become obsolete due to swapping optimization.
For directories, 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 user
In computing, the superuser is a special user account used for system administration. Depending on the operating system (OS), the actual name of this account might be root, administrator, admin or supervisor. In some cases, the actual name of the ...
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.
The modern function of the sticky bit refers to directories, and protects directories and their content from being hijacked by non-owners; this is found in most modern Unix-like systems. Files in a shared directory such as
/tmp
belong to individual owners, and non-owners may not delete, overwrite or rename them.
History
The sticky bit was introduced in the Fifth Edition of
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
(in 1974) for use with pure executable
files.
When set, it instructed the
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
to retain the
text segment of the program in
swap space after the
process
A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic.
Things called a process include:
Business and management
* Business process, activities that produce a specific s ...
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
HP-UX (from "Hewlett Packard Unix") is a proprietary software, proprietary implementation of the Unix operating system developed by Hewlett Packard Enterprise; current versions support HPE Integrity Servers, based on Intel's Itanium architect ...
and
UnixWare.
Solaris appears to have abandoned this in 2005. The 4.4-Lite release of
BSD
The Berkeley Software Distribution (BSD), also known as Berkeley Unix or BSD Unix, is a discontinued Unix operating system developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berkeley, beginni ...
retained the old sticky bit behavior, but it has been subsequently dropped from
OpenBSD
OpenBSD is a security-focused operating system, security-focused, free software, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by fork (software development), forking NetBSD ...
(as of release 3.7) and
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
(as of release 2.2.1). No version of
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
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.
Usage
The most common modern use of the sticky bit is on
directories residing within filesystems for
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
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
In vascular plants, the roots are the plant organ, organs of a plant that are modified to provide anchorage for the plant and take in water and nutrients into the plant body, which allows plants to grow taller and faster. They are most often bel ...
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
Benchmarking is the practice of comparing business processes and performance metrics to industry bests and best practices from other companies. Dimensions typically measured are Project management triangle, quality, time and cost.
Benchmarking is ...
tests.
The sticky bit is also set by the
automounter
An automounter is any program or software facility which automatically mount (computing), mounts filesystems in response to access operations by user programs. An automounter system utility (Daemon (computer software), daemon under Unix), when not ...
to indicate that a file has not been mounted yet. This allows programs like ''ls'' to ignore unmounted remote files.
Examples
The sticky bit can be set using the
chmod
is a shell command for changing access permissions and special mode flags of files (including special files such as directories). The name is short for ''change mode'' where ''mode'' refers to the permissions and flags collectively.
The co ...
command and can be set using its octal mode 1000 or by its symbol t (s is already used by the
setuid
The Unix and Linux access rights flags setuid and setgid (short for ''set user identity'' and ''set group identity'') allow users to run an executable with the file system permissions of the executable's owner or group respectively and to chang ...
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:
$ ls -ld /tmp
drwxrwxrwt 4 root sys 485 Nov 10 06:01 /tmp
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 -):
# ls -l test
-rw-r--r-- 1 root anygroup 0 Nov 10 12:57 test
# chmod +t test; ls -l test
-rw-r--r-T 1 root anygroup 0 Nov 10 12:57 test
See also
*
chmod
is a shell command for changing access permissions and special mode flags of files (including special files such as directories). The name is short for ''change mode'' where ''mode'' refers to the permissions and flags collectively.
The co ...
*
setuid
The Unix and Linux access rights flags setuid and setgid (short for ''set user identity'' and ''set group identity'') allow users to run an executable with the file system permissions of the executable's owner or group respectively and to chang ...
References
External links
Unix File and Directory Permissions 2010, by Wayne Pollock, archived from the original on February 3, 2012
{{DEFAULTSORT:Sticky Bit
Unix file system technology
File system permissions