The Unix file types are the categories of
file format
A file format is a Computer standard, standard way that information is encoded for storage in a computer file. It specifies how bits are used to encode information in a digital storage medium. File formats may be either proprietary format, pr ...
s that a
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 ...
-based system uses to provide context-sensitive behavior of
file system items all of which called ''files'' in Unix-based systems.
POSIX
The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
defines categories: regular,
directory,
symbolic link
In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory (called the "target") by specifying a path thereto.
Symbolic links are supported by POSIX and by most Unix-like operating syste ...
,
FIFO special,
block special, character special, and
socket
Socket may refer to:
Mechanics
* Socket wrench, a type of wrench that uses separate, removable sockets to fit different sizes of nuts and bolts
* Socket head screw, a screw (or bolt) with a cylindrical head containing a socket into which the hexag ...
.
An
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 ...
may define additional categories (e.g. Solaris
doors
A door is a hinged or otherwise movable barrier that allows ingress (entry) into and egress (exit) from an enclosure. The created opening in the wall is a ''doorway'' or ''portal''. A door's essential and primary purpose is to provide secu ...
).
A regular file is any file format that the file system does not know and relies on applications to manipulate. The other categories are for file formats that the file system inherently knows and can manipulate.
The
ls -l
command reports a file's category via the character before the
permissions information. The
file
command reports file format information; even for regular files.
Representations
Numeric
The type of a file is specified by the file's mode, which consists of the file type and
access permissions. The
stat() system call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
returns information about a file in a structure that includes the file mode in a field named . The file types and access permissions are typically defined as macros that expand to octal integer literals, and the field of the structure is typically defined as an unsigned integer variable, which normally has a size of 32 bits, although the C language standard allows it to be implementation-specific. However, commonly 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, only 16 bits (6 octal digits) of the field are used by the octal integer literals that represent different file types and access permissions, where the most significant 4 bits (2 octal digits) are used for the file type, and the remaining 12 bits for the access permissions, which consist of the higher-order 3 bits (1 octal digit) that are used for the setuid, setgid, and sticky attributes, which are commonly referred to as the special permissions, followed by the 9 bits (3 octal digits) that are used for the normal permissions. POSIX specifies the 12 least significant bits of a file's mode to be access permissions, and leaves the file type bits to be an implementation detail.
[
When written as ]octal
Octal (base 8) is a numeral system with eight as the base.
In the decimal system, each place is a power of ten. For example:
: \mathbf_ = \mathbf \times 10^1 + \mathbf \times 10^0
In the octal system, each place is a power of eight. For ex ...
, a mode value shows the Unix file type separately as the first two digits. For example, mode of octal 100644 indicates a regular file since the Unix file type bit-field is octal 10. This format is used in git
Git () is a distributed version control system that tracks versions of files. It is often used to control source code by programmers who are developing software collaboratively.
Design goals of Git include speed, data integrity, and suppor ...
, tar, ar, and other contexts.
A program can test a mode value to determine Unix file type via macros provided in standard C headers. For example, a program can mask a mode value with S_IFMT
(octal 170000 for the first 4 bits convention) to obtain the Unix file type and then test that value against S_IFDIR
to determine whether the file is a directory. Alternatively, a program can use the S_ISDIR
macro. S_IFMT
is not a core POSIX concept, but a X/Open System Interfaces (XSI) extension. Systems conforming to ''only'' POSIX may use some other methods.[
]
Symbolic
POSIX specifies the long format of the command to represent the Unix file type as the first letter for an entry.
The GNU coreutils version of ls
calls the gnulib
Gnulib, also called the GNU portability library, is a collection of software subroutines which are designed to be usable on many operating systems. The goal of the project is to make it easy for free software authors to make their software run o ...
function filemode()
to format the mode string. FreeBSD uses a simpler approach but allows a smaller number of file types.
Examples
Command reports the ''file mode string'' as the first column of output for each file. This string starts with the Unix file type indicator. The following is output for the root directory from command ls -l /
which starts with to indicate that it's a directory. The rest of the first column indicates file permissions.
drwxr-xr-x 26 root root 4096 Sep 22 09:29 /
Output from command stat /
includes the full Unix file type name:
File: "/"
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 802h/2050d Inode: 128 Links: 26
Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
...
Output for a symbolic link file starts with an initial l
(lower case 'L') and identifies the referenced file path as in this example ls -l
output:
lrwxrwxrwx ... termcap -> /usr/share/misc/termcap
lrwxrwxrwx ... S03xinetd -> ../init.d/xinetd
A named pipe is a special file that can be created via the command mkfifo ''name''
. A named pipe is identified as p
as in this example ls -l
output:
prw-rw---- ... mypipe
A socket filepath is a type of Unix domain socket
A Unix domain socket (UDS), a.k.a. local socket, a.k.a. inter-process communication (IPC) socket, is a communication endpoint for exchanging data between processes executing in the same Unix or Unix-like operating system.
The name, ''Unix domain ...
, a special file for inter-process communication
In computer science, interprocess communication (IPC) is the sharing of data between running Process (computing), processes in a computer system. Mechanisms for IPC may be provided by an operating system. Applications which use IPC are often cat ...
that unlike named pipes allows for full duplex. A socket is marked with s
as in this example ls -l
output:
srwxrwxrwx /tmp/.X11-unix/X0
Block and character files represent hardware devices. A device file can be used to control access to a device and to allow file-like operations on the connected device. A character device (serial access) is marked with a c
and a block device (random access) is marked with a b
as in this example ls -l
output:
crw-rw-rw- ... /dev/null
In some operating systems, the null device is a device file that discards all data written to it but reports that the write operation succeeded. This device is called /dev/null on Unix and Unix-like systems, NUL: (see TOPS-20) or NUL on CP/M a ...
brw-rw---- ... /dev/sda
References
{{DEFAULTSORT:Unix File Types
Unix file system technology