Skip to main content
RunBook Academy

LinuxIII · Filesystems and FilesFile types

Linux file types and the seven file kinds

Foundation⏱ ~8 minbashlsstatfile

What you'll learn

  • Identify the seven file kinds on Linux
  • Read `ls -l` output and explain each character of the permission string
  • Recognise when a "file" is actually a device, socket, or pipe
  • Inspect file metadata with stat

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

Everything on a Linux system is a file. That sentence is more than a convenience — it is the abstraction that lets you use the same syscalls, the same tools, and the same mental model for ordinary text files, directories, network sockets, kernel devices, and pipes.

The seven file kinds

Character in ls -lKindWhat it is
-Regular fileBytes on disk. Text, binaries, images, anything.
dDirectoryA special file whose contents are entries pointing to other files.
lSymbolic linkA file whose contents are a path to another file.
bBlock deviceA file representing block-addressable storage (disks, partitions, LVM volumes).
cCharacter deviceA file representing a character-stream device (terminals, /dev/null, /dev/random).
pNamed pipe (FIFO)A file that lets two processes communicate via a kernel buffer.
sSocketA file representing a Unix domain socket — an IPC endpoint.
Read-only / Safethe five file kinds in one command
$ ls -l /etc/passwd /tmp /var/run/sshd.sock /dev/sda /dev/null
-rw-r--r-- 1 root root 3010 Aug  9 11:11 /etc/passwd
drwxr-xr-x 2 root root 4096 Aug  9 11:11 /tmp
srwxrwxr-x 1 root root    0 Aug  9 11:11 /var/run/sshd.sock
brw-rw---- 1 root disk  8, 0 Aug  9 11:11 /dev/sda
crw-rw-rw- 1 root root  1, 3 Aug  9 11:11 /dev/null

Illustrative output

Why it matters

Knowing the file kind is the difference between:

  • “I cannot edit this file” because it is a directory, not a regular file.
  • “I cannot rm this — it is busy” because it is the mount point of a filesystem.
  • “My application fails to start” because the socket it expects is actually a regular file left over from a botched install.
  • “Why does cat /dev/sda print gibberish?” because it is a block device, not a regular file.

Reading file metadata with stat

ls -l shows part of the story. stat shows everything the kernel tracks about a file:

Read-only / Safestat
$ stat /etc/passwd
  File: /etc/passwd
Size: 3010      	Blocks: 8          IO Block: 1024   regular file
Device: 801h/2049d	Inode: 12345       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-08-09 11:11:11 +0000
Modify: 2026-08-09 11:11:11 +0000
Change: 2026-08-09 11:11:11 +0000
Birth: 2024-04-22 12:34:56 +0000

Illustrative output

The three timestamps:

TimestampSet whenUpdated by
atime (access)file is readcat, less, grep
mtime (modify)file content is writtenmost writes
ctime (change)inode metadata is writtenchmod, chown, rename

The file command

When you do not know what a file is, file reads its magic bytes and guesses. It is not perfect — it pattern-matches on signatures, not on intent — but it is the fastest first answer.

Read-only / Safefile
$ file /bin/bash /etc/passwd /var/run/docker.sock
/bin/bash:               ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked
/etc/passwd:              Unicode text, UTF-8 text
/var/run/docker.sock:     socket

Illustrative output

Knowledge check

Knowledge check · 3 questions

  1. Q1. What is the leading character of the permission string when `ls -l` shows a socket?

  2. Q2. Reading a file can update its atime, but never its mtime.

  3. Q3. Which of the following are file kinds on Linux? Select all that apply.

Passing score: 75%. Answers are checked in this browser.