Frequently Asked Question

What are the seven file types in Linux and how do I tell them apart?

Linux recognises seven kinds of file, and the first character of ls -l tells you which is which. A dash (-) is a regular file, a plain stream of bytes, whether that be text, an executable, or a JPEG. A d is a directory, which is really a file whose contents are name-to-inode mappings. An l is a symbolic link, a file whose contents are a path to another file. A c is a character device like /dev/tty or /dev/null, which transfers data one byte at a time. A b is a block device like /dev/sda, which transfers data in fixed-size blocks. A p is a named pipe (FIFO), a one-way channel between processes. An s is a socket, a bidirectional IPC endpoint such as /var/run/docker.sock.

Regular files and directories make up almost everything you touch on a day-to-day basis; symlinks are next. The device, FIFO, and socket entries live mostly under /dev, /run, and /var/run, and exist because Unix wanted a single uniform name space for every kind of I/O endpoint. If you want to confirm what something really is, stat will print the type explicitly and file will sniff the content.

Further reading and video