language-icon Old Web
English
Sign In

Unix file types

The standard Unix file types are regular, directory, symbolic link, FIFO special, block special, character special, and socket as defined by POSIX. Different OS-specific implementations allow more types than what POSIX requires (e.g. Solaris doors). A file's type can be identified by the ls -l command, which displays the type in the first character of the file system permissions field. The standard Unix file types are regular, directory, symbolic link, FIFO special, block special, character special, and socket as defined by POSIX. Different OS-specific implementations allow more types than what POSIX requires (e.g. Solaris doors). A file's type can be identified by the ls -l command, which displays the type in the first character of the file system permissions field. 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. However, the file command can be used to determine what type of data they contain. Take for example one line in the ls -l output: POSIX specifies the format of the output for the long format (-l option). In particular, the first field (before the first space) is dubbed the 'file mode string' and its first character describes the file type. The rest of this string indicates the file permissions. Therefore, in the example, the mode string is drwxr-xr-x: the file type is d (directory) and the permissions are rwxr-xr-x. Internally, ls obtains the stat structure associated with the file and transforms the mode_t field into a human-readable format.Note that mode_t is actually a bit field with two parts; the file type is stored within the S_IFMT mask.It can be tested with some macros like S_ISDIR (for the S_IFDIR value with mask S_IFMT) to get the file type flags. The GNU coreutils version of ls uses a call to filemode(), a glibc function (exposed in the gnulib library) to get the mode string. FreeBSD uses a simpler approach but allows a smaller number of file types. Regular files show up in ls -l with a hyphen-minus - in the mode field:

[ "Stub file", "Sparse file", "unix file system", "Extended file attributes", "Kernel panic", "ZAP File" ]
Parent Topic
Child Topic
    No Parent Topic
Baidu
map