Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Unix file types
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|File format categories built-in to a Unix-based file system}} The '''Unix file types''' are the categories of [[file format]]s that a [[Unix]]-based system uses to provide context-sensitive behavior of [[file system]] items {{endash}} all of which called ''files'' in Unix-based systems. [[POSIX]] defines categories: regular, [[Directory (computing)|directory]], [[symbolic link]], [[Named pipe|FIFO special]], [[Device file|block special, character special]], and [[Unix domain socket|socket]].<ref name=stath>{{cite web |url=http://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_stat.h.html |title=<sys/stat.h> |website=The Open Group Base Specifications Issue 8 |publisher=The Open Group |date=14 June 2024 |access-date=1 June 2025 |archive-date=25 April 2025 |archive-url=https://web.archive.org/web/20250425091636/https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_stat.h.html |url-status=live }}</ref> An [[operating system]] may define additional categories (e.g. Solaris [[Doors (computing)|doors]]). A regular file is any file format that the file system does not know and relies on applications to manipulate.<ref>{{cite book |last1=Loukides |first1=Mike |title=Unix Power Tools |date=October 2002 |publisher=O'Reilly |isbn=9780596003302 |page=80 |edition=3 |chapter=When Is a File Not a File? |quote=A file is nothing more than a stream of bytes ...}}</ref> The other categories are for file formats that the file system inherently knows and can manipulate. The [[ls|<code>ls -l</code>]] command reports a file's category via the character before the [[File-system permissions#Notation of traditional Unix permissions|permissions]] information. The [[File (command)|<code>file</code>]] command reports file format information; even for regular files.<ref>{{cite web |url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/file.html |title=<code>file</code> |publisher=[[The Open Group]] |work=IEEE Std 1003.1-2017 ([[POSIX]]) |date=2018 |access-date=2023-10-26 |archive-date=2018-10-12 |archive-url=https://web.archive.org/web/20181012025917/https://pubs.opengroup.org/onlinepubs/9699919799/utilities/file.html |url-status=live }}</ref> == Representations == === Numeric === The type of a file is specified by the file's mode, which consists of the file type and [[File-system permissions|access permissions]]. The [[stat (system call)|stat()]] [[system call]] returns information about a file in a {{code|stat}} structure that includes the file mode in a field named {{code|st_mode}}. The file types and access permissions are typically defined as macros that expand to octal integer literals, and the {{code|st_mode}} field of the {{code|stat}} 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]] systems, only 16 bits (6 octal digits) of the {{code|st_mode}} 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.<ref name=stath/> When written as [[octal]], a mode value shows the Unix file type separately {{endash}} 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]], [[tar (computing)|tar]], [[ar (Unix)|ar]], and other contexts.<ref>{{cite web |last1=Kitt |first1=Stephen |title=What file mode is a symlink? |url=https://unix.stackexchange.com/a/193468 |website=Unix & Linux Stack Exchange}}</ref> A program can test a mode value to determine Unix file type via macros provided in standard [[C (programming language)|C]] headers. For example, a program can mask a mode value with <code>S_IFMT</code> (octal 170000 for the first 4 bits convention) to obtain the Unix file type and then test that value against <code>S_IFDIR</code> to determine whether the file is a directory. Alternatively, a program can use the <code>S_ISDIR</code> macro. <code>S_IFMT</code> is not a core POSIX concept, but a X/Open System Interfaces (XSI) extension. Systems conforming to ''only'' POSIX may use some other methods.<ref name=stath/> === Symbolic === POSIX specifies the long format of the {{code|ls}} command to represent the Unix file type as the first letter for an entry.<ref name="ls">{{cite web |url=http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html |work=IEEE Std 1003.1-2008 ([[POSIX]]) |title=<code>ls</code> |publisher=The Open Group |date=11 March 2017 |access-date=10 February 2017 |archive-date=3 August 2017 |archive-url=https://web.archive.org/web/20170803094750/http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html |url-status=live }}</ref> {{Table alignment}} {| class="wikitable col2center" |+ Unix file type indicators |- ! type !! symbol |- | regular || - |- | directory || d |- | symbolic link || l |- | FIFO special || p |- | block special || b |- | character special || c |- | socket || s |} The [[GNU Core Utilities|GNU coreutils]] version of <code>ls</code> calls the [[gnulib]] function <code>filemode()</code><ref>{{cite web |url=https://github.com/coreutils/gnulib/blob/master/lib/filemode.c |title=filemode function in GNU coreutils |publisher=GNU |date=11 March 2017}}</ref> to format the mode string. FreeBSD uses a simpler approach but allows a smaller number of file types.<ref>{{cite web |url=https://github.com/freebsd/freebsd/blob/8e401abc421060406354c05d494b887f91849b6d/bin/ls/print.c#L557 |title=printtype function from FreeBSD |publisher=FreeBSD |date=11 March 2017}}</ref> ==Examples== Command {{code|ls -l}} 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 <code>ls -l /</code> which starts with {{code|d}} to indicate that it's a directory. The rest of the first column {{code|rwxr-xr-x}} indicates file permissions. '''d'''rwxr-xr-x 26 root root 4096 Sep 22 09:29 / Output from command <code>stat /</code> 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/'''d'''rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) ... Output for a symbolic link file starts with an initial <code>'''l'''</code> (lower case 'L') and identifies the referenced file path as in this example <code>ls -l</code> output:<ref name="ls" /> '''l'''rwxrwxrwx ... termcap -> /usr/share/misc/termcap '''l'''rwxrwxrwx ... S03xinetd -> ../init.d/xinetd A named pipe is a special file that can be created via the command <code>[[mkfifo]] ''name''</code>. A named pipe is identified as <code>'''p'''</code> as in this example <code>ls -l</code> output:<ref name="ls" /> '''p'''rw-rw---- ... mypipe A socket filepath is a type of [[Unix domain socket]], a special file for [[inter-process communication]] that unlike named pipes allows for full [[Duplex_(telecommunications)|duplex]]. A socket is marked with <code>'''s'''</code> as in this example <code>ls -l</code> output:<ref name="ls" /> '''s'''rwxrwxrwx /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 <code>'''c'''</code> and a block device (random access) is marked with a <code>'''b'''</code> as in this example <code>ls -l</code> output:<ref name="ls" /> '''c'''rw-rw-rw- ... [[/dev/null]] '''b'''rw-rw---- ... [[/dev/sda]] ==References== {{Reflist}} {{DEFAULTSORT:Unix File Types}} [[Category:Unix file system technology]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Endash
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Table alignment
(
edit
)