Kahibaro
Discord Login Register

File types

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:

How Linux Represents File Types

When you run:

ls -l

you’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/card0

The very first character on each line shows the file type:

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”:

In ls -l, these start with -:

-rw-r--r-- 1 alice users  1234 Dec 12 10:00 notes.txt

Key points

Do:

Don’t:

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

Do:

Don’t:

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

When you use docs, the system transparently uses /data/docs instead.

Types of symlinks

Key points

Typical uses:

Do:

Don’t:

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:

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/ttyS0

Character devices (`c`)

They are typically used for streaming data, not random access.

Block devices (`b`)

These are used by filesystems such as EXT4, XFS, etc.

Key points

Do:

Don’t:

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

Example creation (for illustration, you’ll learn commands like this later):

mkfifo mypipe

Then, in two terminals:

Terminal 1:

cat > mypipe

Terminal 2:

cat mypipe

Text you type in terminal 1 appears in terminal 2.

Key points

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

Key points

Do:

Don’t:

Summary Table of File Types

Typels -l prefixDescriptionCommon Location Examples
Regular-Normal files (text, binaries, etc.)Everywhere
DirectorydContains other files/directories/, /home, /etc, /usr
SymlinklPointer/shortcut to another file/pathAnywhere
Char devcCharacter device (streaming I/O)/dev/tty*, /dev/random
Block devbBlock device (disks, partitions)/dev/sda, /dev/nvme0n1p1
FIFO/pipepNamed pipe for one-way process commsOften /tmp/, custom locations
SocketsIPC endpoint for services/run/, /var/run/, /tmp/

Practical Tips for Beginners

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.

Views: 22

Comments

Please login to add a comment.

Don't have an account? Register now!