Unix file typesThe seven standard Unix file types are regular, directory, symbolic link, FIFO special, block special, character special, and socket as defined by POSIX.[1] Different OS-specific implementations allow more types than what POSIX requires (e.g. Solaris doors). A file's type can be identified by the For regular files, Unix does not impose or provide any internal file structure; therefore, their structure and interpretation is entirely dependent on the software using them.[2] However, the RepresentationsNumericIn the stat structure, file type and permissions (the mode) are stored together in a By convention, the mode is a 16-bit value written out as a six-digit octal number without a leading zero. The format part occupies the lead 4-bits (2 octal digits), and "010" (1000 in binary) usually stands for a regular file. The next 3 bits (1 digit) are usually used for setuid, setgid, and sticky. The last part is already defined by POSIX to contain the permission. An example is "100644" for a typical file. This format can be seen in git, tar, and ar, among other places.[4] The type of a file can be tested using macros like Mode stringTake for example one line in the drwxr-xr-x 2 root root 0 Jan 1 1970 home POSIX specifies[5] the format of the output for the long format ( Examples of implementationsThe GNU coreutils version of FreeBSD uses a simpler approach but allows a smaller number of file types.[7] Directory
The most common special file is the directory. The layout of a directory file is defined by the filesystem used. As several filesystems are available under Unix, both native and non-native, there is no one directory file layout. A directory is marked with a $ ls -dl / drwxr-xr-x 26 root root 4096 Sep 22 09:29 / $ stat / 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) ... Symbolic link
A symbolic link is a reference to another file. This special file is stored as a textual representation of the referenced file's path (which means the destination may be a relative path, or may not exist at all). A symbolic link is marked with an lrwxrwxrwx ... termcap -> /usr/share/misc/termcap lrwxrwxrwx ... S03xinetd -> ../init.d/xinetd FIFO (named pipe)
One of the strengths of Unix has always been inter-process communication. Among the facilities provided by the OS are pipes, which connect the output of one process to the input of another. This is fine if both processes exist in the same parent process space, started by the same user, but there are circumstances where the communicating processes must use FIFOs, here referred to as named pipes. One such circumstance occurs when the processes must be executed under different user names and permissions. Named pipes are special files that can exist anywhere in the file system. They can be created with the command A named pipe is marked with a prw-rw---- ... mypipe SocketA socket is a special file used for inter-process communication, which enables communication between two processes. In addition to sending data, processes can send file descriptors across a Unix domain socket connection using the Unlike named pipes which allow only unidirectional data flow, sockets are fully duplex-capable. A socket is marked with an srwxrwxrwx /tmp/.X11-unix/X0 Device file (block, character)
In Unix, almost all things are handled as files and have a location in the file system, even hardware devices like hard drives. The great exception is network devices, which do not turn up in the file system but are handled separately. Device files are used to apply access rights to the devices and to direct operations on the files to the appropriate device drivers. Unix makes a distinction between character devices and block devices. The distinction is roughly as follows:
Although, for example, disk partitions may have both character devices that provide un-buffered random access to blocks on the partition and block devices that provide buffered random access to blocks on the partition. A character device is marked with a crw-rw-rw- ... /dev/null brw-rw---- ... /dev/sda References
Information related to Unix file types |