Table of Contents
Understanding File Types in Linux
Linux doesn’t just store “files” — it stores different kinds of files, each with a specific purpose. Knowing these types helps you understand what you’re looking at when you list directories, and prevents mistakes like trying to “edit” a device or “run” a text document.
This chapter focuses on:
- What major file types exist in Linux
- How to recognize them (especially using
ls -l) - What they are typically used for
- Basic do’s and don’ts for each type
How Linux Represents File Types
When you run:
ls -lyou’ll see a listing like:
-rw-r--r-- 1 alice users 1234 Dec 12 10:00 notes.txt
drwxr-xr-x 2 alice users 4096 Dec 12 09:58 projects
lrwxrwxrwx 1 alice users 11 Dec 12 10:05 docs -> /data/docs
crw-rw---- 1 root video 226, 0 Dec 12 09:00 /dev/dri/card0The very first character on each line shows the file type:
-regular fileddirectorylsymbolic linkccharacter devicebblock devicepnamed pipe (FIFO)ssocket
The rest of the characters (rw-r--r-- etc.) are permissions, which are covered elsewhere.
We’ll walk through each file type.
Regular Files (`-`)
What they are
Regular files are what most people think of as “files”:
- Text documents (
.txt,.md) - Executable programs and scripts (
/bin/ls,script.sh) - Images, audio, video, archives (
.png,.mp3,.tar.gz) - Configuration files (often in
/etc)
In ls -l, these start with -:
-rw-r--r-- 1 alice users 1234 Dec 12 10:00 notes.txtKey points
- Contents are just a sequence of bytes; Linux doesn’t care about “extensions”.
- Whether something is executable is determined by permissions, not filename.
Do:
- Edit text configuration and document files with a text editor.
- Make scripts/programs executable if they’re meant to be run.
Don’t:
- Randomly open binary files in a text editor and save changes — you can corrupt them.
Directories (`d`)
What they are
A directory is a special file that stores a list of names and references to other files and directories.
Example from ls -l:
drwxr-xr-x 2 alice users 4096 Dec 12 09:58 projects
Here, d means it’s a directory.
Key points
- “Folders” in graphical file managers are directories.
- Directories form the tree of the filesystem (covered in other chapters).
- You “enter” a directory with
cd, not by executing it.
Do:
- Use commands like
cd,ls,mkdir,rmdirto work with directories.
Don’t:
- Try to open directories as if they were regular files in most editors; that’s not how you inspect contents.
Symbolic Links (`l`)
What they are
A symbolic link (symlink) is a shortcut that points to another file or directory.
In ls -l:
lrwxrwxrwx 1 alice users 11 Dec 12 10:05 docs -> /data/docs- The
lat the beginning means “link”. - After the name, you’ll see
-> target.
When you use docs, the system transparently uses /data/docs instead.
Types of symlinks
- Absolute symlink: points to a full path (
/data/docs) - Relative symlink: points relative to its own directory (
../shared/docs)
Key points
- If the target is deleted or moved, the symlink becomes broken:
ls -lwill show something likedocs -> /missing/path(often colored differently).- Permissions you see on the link itself are usually not meaningful; access is controlled by the target’s permissions.
Typical uses:
- Creating shorter/more convenient paths:
ln -s /very/long/path/project ~/project- Pointing a generic name to a versioned file:
python -> python3.12- Redirecting configuration or data directories.
Do:
- Use symlinks to avoid copying data when you just need multiple names.
- Be aware of whether you’re modifying the target or the link itself.
Don’t:
- Rely on symlinks without knowing where they point:
- Use
ls -lto see the target.
Device Files (`c` and `b`)
Linux represents hardware devices as special files, usually in /dev. Programs interact with these files to talk to hardware.
In ls -l, they appear as:
c— character deviceb— block device
You’ll also see two numbers, like 8, 0 (major and minor device numbers).
Example:
brw-rw---- 1 root disk 8, 0 Dec 12 09:00 /dev/sda
crw-rw---- 1 root dialout 4, 64 Dec 12 09:00 /dev/ttyS0Character devices (`c`)
- Handle data one character (or small chunk) at a time.
- Examples:
- Serial ports (
/dev/ttyS0) - Terminals (
/dev/tty) - Some input devices
They are typically used for streaming data, not random access.
Block devices (`b`)
- Handle data in blocks, allowing random access.
- Examples:
- Hard drives and SSDs (
/dev/sda,/dev/nvme0n1) - Partitions (
/dev/sda1) - USB storage devices (
/dev/sdb)
These are used by filesystems such as EXT4, XFS, etc.
Key points
- These are not “files” with text; they represent hardware.
- Regular users typically should not write directly to device files.
Do:
- Read information about devices with specialized tools (
lsblk,blkid, etc.). - Let system utilities (formatting, mounting, etc.) operate on these device files.
Don’t:
- Run something like
cat /dev/sdaorecho something > /dev/sdaon a disk you care about — you can destroy data. - Try to edit
/dev/*files in a text editor.
Named Pipes / FIFOs (`p`)
What they are
A named pipe (FIFO) is a special file for one-way communication between processes. Data written on one end can be read from the other, in order.
In ls -l:
prw-r--r-- 1 alice users 0 Dec 12 10:10 mypipe
The p at the beginning means FIFO (First-In, First-Out).
How they behave
- They act like a pipe (
|) but with a name in the filesystem. - One process writes to the FIFO, another reads from it.
- Data typically doesn’t “stay” in the FIFO; it’s passed through.
Example creation (for illustration, you’ll learn commands like this later):
mkfifo mypipeThen, in two terminals:
Terminal 1:
cat > mypipeTerminal 2:
cat mypipeText you type in terminal 1 appears in terminal 2.
Key points
- Useful for connecting programs that expect filenames rather than using the
|pipe directly. - Mostly used in scripting and system-level work.
Sockets (`s`)
What they are
A socket file is used for inter-process communication (IPC), often for local network-like communication between programs on the same machine.
In ls -l:
srw-rw-rw- 1 root root 0 Dec 12 09:00 /run/systemd/private
The s means socket.
Typical uses
- Many system services provide a local socket instead of (or in addition to) a network port:
- MySQL:
/var/run/mysqld/mysqld.sock - Docker:
/var/run/docker.sock - Programs connect to these socket files to talk to the service.
Key points
- Sockets are endpoints for communication, not files you edit.
- They often live in
/run,/var/run, or under/tmp.
Do:
- Be aware that some tools can connect via “UNIX socket” instead of TCP/IP.
Don’t:
- Attempt to read/write socket files with normal text tools unless a program specifically expects that.
Summary Table of File Types
| Type | ls -l prefix | Description | Common Location Examples |
|---|---|---|---|
| Regular | - | Normal files (text, binaries, etc.) | Everywhere |
| Directory | d | Contains other files/directories | /, /home, /etc, /usr |
| Symlink | l | Pointer/shortcut to another file/path | Anywhere |
| Char dev | c | Character device (streaming I/O) | /dev/tty*, /dev/random |
| Block dev | b | Block device (disks, partitions) | /dev/sda, /dev/nvme0n1p1 |
| FIFO/pipe | p | Named pipe for one-way process comms | Often /tmp/, custom locations |
| Socket | s | IPC endpoint for services | /run/, /var/run/, /tmp/ |
Practical Tips for Beginners
- Use
ls -loften to learn to recognize file types at a glance. - Before deleting or editing something unusual (like in
/dev,/run,/proc), check the first character inls -land think: - Is this a regular file, or something special?
- Treat device files, FIFOs, and sockets as system-level tools, not user documents.
As you work more with Linux, these file types will feel natural, and you’ll quickly know what you can safely open, edit, or run.