$_ CLI In Depth
Learning progress 0%
lesson filesystem inodes navigation

File Types: Regular, Directory, Device, FIFO & Socket

6 min read Module 2: Filesystem Navigation & Inodes Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:15

The type is part of the inode

The mode field of an inode contains a few bits that identify the file type, and the rest of the mode holds the permissions. The kernel checks the type before it applies a system call. Opening a directory for writing as if it were a file fails, and reading a socket with cat does not give you a file. The file type is set when the inode is created and does not change for the life of the inode.

The long listing shows the type as the first character of each line. The most common values are the hyphen for a regular file, the letter d for a directory, and the letter l for a symbolic link. The others are c for a character device, b for a block device, p for a named pipe, and s for a socket. The command stat -c %F prints the same information as words.

BASH2 lines
stat -c '%F' /etc /dev/null /etc/hostname 2>/dev/null
ls -l /dev/null

The directory /etc is reported as a directory. The device /dev/null is a character special file. Its listing starts with c, and the two numbers before the date are its major and minor device numbers, which identify the driver and the particular device.

Regular files and directories

A regular file is the type most people mean by a file. Its data is a sequence of bytes, and the filesystem maps those bytes to blocks. Most programs work only with regular files, which is why many tools fail or behave oddly when given a device or a FIFO. A directory is also a file to the kernel, but its contents are records of names and inode numbers, as the earlier unit explained. The kernel allows only a few operations on a directory, such as listing it and looking up names within it.

Symbolic links

A symbolic link is a file whose data is a path. It is listed with the type l, and it can point at any type of inode, including a directory or a device. The kernel follows it during path lookup, so most programs never see the link as a link unless they ask. Tools such as ls -l, stat, and find -type l can tell them apart. The option -L in many commands tells them to follow links.

Device files

A character device transfers data one byte at a time, such as a terminal or a random number generator, and a block device transfers fixed-size blocks, such as a disk. Each device file contains a major number, which selects the driver, and a minor number, which selects the specific device that the driver manages. You rarely create device files by hand on a modern system, because the kernel and the device manager create them when hardware appears. Creating one requires privileges. The unprivileged lab cannot make new device nodes, but it can read the existing ones.

The device /dev/null is the simplest example. It accepts writes and discards them, and reads return end of file. The device /dev/zero returns an endless stream of zero bytes, which is useful for making test files of a chosen size. Both are character devices.

Named pipes (FIFOs)

A named pipe is created with mkfifo. It appears in the directory tree with the type p, but it holds no data on disk. Opening it for reading blocks until a writer opens it, and the reverse. The kernel moves bytes from the writer to the reader through memory. A FIFO gives two unrelated programs a rendezvous point in the filesystem, which an anonymous pipe made by the shell cannot do. Anonymous pipes, the vertical bar between commands, are covered in the process module.

BASH4 lines
cd /workspace
mkfifo demo-pipe
ls -l demo-pipe
stat -c '%F' demo-pipe

Sockets

A Unix domain socket is an endpoint for communication between processes on the same machine. It appears as a file of type s, and programs connect to it by name. The Docker client and many system services use this mechanism, and you will often see sockets under /run. The socket file does not contain the messages. The kernel handles them in memory, and the file is only the rendezvous point. A socket exists only while a process has it open, so a stale socket file left behind by a crashed program can block a new one from starting.

Tip

When a command reports that it expected a regular file and got something else, run stat -c %F on the path first. It tells you immediately whether you have a device, a pipe, a socket, or a link.

Why the type matters to a program

Most programs check the type before they act, and many fail with a message that looks confusing until you know the type. A tool that copies a file reads from it until end of file, so pointing it at a FIFO blocks until a writer appears, and pointing it at a character device may read forever. A program that expects a directory and finds a symbolic link to a file must decide whether to follow the link. The type therefore decides whether a command is safe to run on a given path, and checking it first is a good habit in scripts.

The same reasoning applies to device files. Writing to the wrong device can destroy data, so a script that accepts a path from a user should check the type before it writes. The test -f accepts only regular files, which is a safer default than testing for existence alone.

Finding files by type

Later modules use find -type with the letters f, d, l, p, s, c, and b to select entries by type. The same letters appear in the long listing, so the vocabulary carries over. Use the type test whenever you want to act on files of one kind and leave the others alone.

Practice in the lab

In the lab you will create a named pipe, read the type of a device file, and then find a symbolic link by type. The checks look at the output that you save, so the evidence matches the type the kernel reports.

Visualizer

A directory is a list of (name, inode number) pairs. The inode holds the file itself. Hard links add names; symlinks store a path.

1 / 5
directory /workspace
nameinode
a1201
inode table
inodetypelinksdata
1201regular1"hi\n"

echo hi > a allocates inode 1201 and adds the entry a → 1201 to the directory. The link count is 1.

cd /workspace; echo hi > a; ln a b; ls -li a b; rm a; cat b; stat -c "%h links" b
Terminal lab · 3 steps · real Linux in your browser

Find entries by type

Create a named pipe, a symbolic link, and a regular file, then find each one by type.

01
Find the named pipe
The directory types holds a regular file, a named pipe, and a symbolic link. Save the names of the pipes: ``bash find types -maxdepth 1 -type p > fifos.txt ``
Show hint for step 1
The find test -type p selects named pipes.
02
Read the type of a device
Save the type of /dev/null as a word: ``bash stat -c %F /dev/null > device.txt ``
Show hint for step 2
stat -c %F prints the file type. /dev/null is a device file.
03
Find the symbolic link
Save the names of the symbolic links in types: ``bash find types -maxdepth 1 -type l > links.txt ``
Show hint for step 3
The find test -type l selects symbolic links.
Check yourself Question 1 of 4
Concept Check Named pipe in ls recall

Which character starts the ls -l line for a named pipe?

Recap & Key Takeaways

The file type is stored in the inode, and the first character of ls -l shows it: - regular, d directory, l link, c and b devices, p FIFO, s socket.
Device files connect a name to a driver through major and minor numbers, and /dev/null discards everything written to it.
A named pipe is a rendezvous point with no data on disk, and a socket is an in-memory channel between processes.
stat -c %F prints the type as a word, and find -type selects entries by type.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue