Theory
Everything is a file
Linux is built on a strikingly simple idea: almost everything is a file. Your text documents are files, obviously. But so are your compiled programs, your directories, and even your hardware devices, the keyboard, the disk, the terminal, all appear as files you can read from and write to.
This 'everything is a file' philosophy means one consistent set of tools and ideas works across the whole system. This lesson introduces the kinds of files Linux has, and shows how to tell them apart at a glance, which you will rely on constantly.
Theory
The main file types
Linux files fall into a few types:
Regular files hold ordinary data. These split into text files (human-readable: scripts, configuration, notes) and binary files (machine data: compiled programs, images).
Directories are themselves a type of file, a file whose contents are a list of other files. That is how folders nest.
Special files represent things that are not plain data. The most important are device files: your hardware appears here (for example a disk or a terminal), so the same read and write operations work on devices as on documents. Other special files include symbolic links (pointers to other files), named pipes, and sockets.
Formula
The first character of ls -l is the type
When you run ls -l, each line begins with a block of characters like -rwxr-xr-x. That very first character tells you the file type:
- regular file, d directory, l symbolic link, c character device, b block device, p named pipe, s socket.
So before you even read the name, one glance at the first character tells you what kind of thing you are looking at. This is a habit worth building early.
Practical
Reading file types from ls -l
$ ls -l /etc/hostname /bin /dev/null
-rw-r--r-- 1 root root 13 ... /etc/hostname # - regular (text) file
lrwxrwxrwx 1 root root 7 ... /bin -> usr/bin # l symbolic link
crw-rw-rw- 1 root root ... /dev/null # c character device
# First character: -=regular d=directory l=link c=char device b=blockQuiz
An ls -l listing shows a line beginning with the character 'd'. What kind of file is it?
- A device file, because 'd' stands for device
- A directory, because the leading 'd' marks a directory
- A regular data file
- A symbolic link
Show the answer
A directory, because the leading 'd' marks a directory
The leading 'd' in an ls -l listing marks a directory, a file whose contents are a list of other files. Option A is a natural-looking trap: 'd' does NOT mean device; device files are shown by 'c' (character device) or 'b' (block device). Option C is wrong because a regular file is shown by a leading '-', not 'd'. Option D is wrong because a symbolic link is shown by a leading 'l'. Memorise the common first characters: '-' regular, 'd' directory, 'l' link, 'c' and 'b' devices. That single character is the quickest way to know what you are dealing with.
Think first
Why treat devices as files at all?
A hard disk is not a document. Why does Linux make your keyboard, disk, and terminal appear as files? Then tap.
Show the answer
Because it lets ONE simple, consistent set of tools work on everything, which is enormously powerful. If a device behaves like a file, then the same operations you already know, read, write, and the same commands, cat, cp, redirection, work on hardware too, with no special new interface to learn. Want to send text to a terminal? Write to its file. Want to read raw data from a disk or discard output? Read from or write to the right device file (like /dev/null, the 'throw it away' file). Programs do not need special cases for 'is this a file or a device?'; they just read and write, and the kernel routes it appropriately. This uniformity is why Linux commands compose so beautifully: because directories, documents, and devices all speak the same 'file' language, tools built for one work on the others. It is a single elegant abstraction that removes enormous complexity, which is exactly why 'everything is a file' is considered one of the great design ideas of Unix and Linux. One interface to rule them all.
Summary
Key takeaways
- Linux follows an 'everything is a file' philosophy: data, directories, and even devices are accessed as files.
- Regular files hold data: text files (human-readable) and binary files (machine data like programs).
- Directories are files whose contents list other files; that is how folders nest.
- Special files include device files (hardware as files), symbolic links, named pipes, and sockets.
- The first character of an ls -l line gives the type: '-' regular, 'd' directory, 'l' link, 'c' char device, 'b' block device.
- Treating devices as files lets the same commands and read/write operations work across the whole system.
- Memory hook: one glance at the first ls -l character tells you the file type.