Table of Contents
Understanding `/dev`
The /dev directory is where Linux exposes hardware and certain virtual resources as files called device nodes or device files. Instead of talking directly to raw hardware, programs read from and write to these special files, and the kernel/device drivers handle the rest.
This chapter focuses on what makes /dev unique, how device files are organized, and how you can safely interact with them as a beginner.
Key ideas about `/dev`
- Device files are not regular files on disk storing user data.
- Most entries in
/devare created and managed automatically by the system (usually viaudev). - Many
/deventries correspond to real hardware (disks, USB devices, audio, etc.), while others are purely virtual.
You normally do not create or delete entries in /dev manually; doing so is reserved for advanced administration and special cases.
Types of device files: character vs block
Device files come in two main types:
- Character devices
- Handle data one character (byte) at a time, in a stream.
- Examples: serial ports, keyboards, mice, terminals, some virtual devices.
- Block devices
- Handle data in fixed-size blocks (e.g. 512 bytes, 4KB).
- Typically correspond to storage devices.
- Examples: hard drives, SSDs, USB sticks, partitions.
You can check the type with ls -l:
$ ls -l /dev/null /dev/sda
crw-rw-rw- 1 root root 1, 3 Dec 12 10:00 /dev/null
brw-rw---- 1 root disk 8, 0 Dec 12 10:00 /dev/sda- Lines starting with
care character devices. - Lines starting with
bare block devices. - The two numbers before the date (e.g.
1, 3or8, 0) are the major and minor device numbers, used internally by the kernel to identify the device driver and the specific device instance.
As a beginner, you usually don’t need to manipulate these numbers; just recognize that they make device files special.
Automatic device management (`udev`)
Modern Linux systems dynamically populate /dev:
- When you plug in a USB drive, a corresponding
/deventry (e.g./dev/sdb,/dev/sdb1) appears. - When you unplug it, the entry disappears.
- On boot, the kernel detects hardware and
udevcreates the appropriate device files.
You might see temporary names for newly attached devices, but under normal use you’ll rely on stable names or higher-level tools (like your file manager or disk utilities) rather than interacting with /dev directly.
Common categories under `/dev`
While /dev can contain many entries, a few categories are especially useful to understand.
Storage devices: `/dev/sd*`, `/dev/nvme*`, `/dev/mapper/*`
These are some of the most important devices, because they represent your disks and partitions.
- SCSI/SATA/USB disks:
/dev/sda,/dev/sdb, etc. - Whole devices:
/dev/sda,/dev/sdb, … - Partitions:
/dev/sda1,/dev/sda2, … - NVMe SSDs (common on newer systems):
- Whole device:
/dev/nvme0n1 - Partitions:
/dev/nvme0n1p1,/dev/nvme0n1p2, … - Device mapper / LVM / encrypted devices:
/dev/mapper/*(e.g./dev/mapper/vg0-root,/dev/mapper/cryptroot)
These entries are used when formatting, checking, or mounting filesystems. You typically access them indirectly via partitioning and mounting tools, not by reading/writing them directly.
Terminals and consoles: `/dev/tty*`, `/dev/pts/*`, `/dev/console`
Linux treats terminals as devices:
/dev/tty- Refers to your current terminal.
- Useful in scripts or commands that need to explicitly send output to the user’s terminal.
/dev/tty1,/dev/tty2, …- Virtual consoles (the text-only screens you can usually access with
Ctrl+Alt+F1,Ctrl+Alt+F2, etc., depending on distribution and configuration). /dev/pts/*- Pseudo-terminals used by terminal emulators (such as GNOME Terminal, Konsole, etc.) and remote sessions (SSH).
- Each open terminal window/tab gets its own
/dev/pts/Ndevice. /dev/console- Represents the system console; important for kernel and early-boot messages.
As a user, you rarely need to manipulate these directly, but they explain how Linux represents text terminals internally.
Special “virtual” devices: `/dev/null`, `/dev/zero`, `/dev/random`, `/dev/urandom`
These devices don’t correspond to physical hardware but are extremely useful tools.
`/dev/null` — the “black hole”
- Discards all data written to it.
- Reading from it returns end-of-file immediately.
- Commonly used to suppress output:
# Discard standard output
command > /dev/null
# Discard both standard output and standard error
command > /dev/null 2>&1`/dev/zero` — infinite zero bytes
- Reading from it returns as many
\0bytes as requested. - Often used for creating empty, zero-filled files for testing or disk images:
# Create a 10 MB file filled with zeros
dd if=/dev/zero of=empty.img bs=1M count=10`/dev/random` and `/dev/urandom` — random data
- Provide random bytes, typically used for cryptography and testing.
/dev/random- Blocks (waits) if there is not enough “entropy” (randomness) available.
- Traditionally considered more conservative for high-security uses, but on modern Linux systems, the distinction is less critical due to improvements in the kernel’s random number generator.
/dev/urandom- Non-blocking: it does not wait for more entropy.
- Commonly used for generating keys, tokens, etc., when you need randomness without stalling.
Basic use example (don’t run blindly without understanding what this does):
# Generate 16 bytes of random data, base64-encoded
head -c 16 /dev/urandom | base64Audio, input, and other hardware
Depending on your system, you’ll see several hardware-related entries:
- Sound:
/dev/snd/*,/dev/dsp(older systems)- Used by sound servers/drivers (e.g. ALSA, PulseAudio, PipeWire).
- Input devices:
/dev/input/*(keyboards, mice, touchpads, joysticks)- Applications rarely access these directly; it’s more common in specialized software or debugging.
- Graphics and GPUs:
/dev/dri/*for Direct Rendering Infrastructure devices (GPUs).- Used by graphics stacks and display servers.
- USB / serial:
/dev/ttyUSB,/dev/ttyACMfor USB serial devices (e.g. Arduino, USB modems, serial adapters)./dev/serial/*may provide friendlier names on some systems.
Again, normal desktop users interact with these through higher-level software: sound servers, display servers, or applications that know how to talk to these devices.
Permissions and access control in `/dev`
Device files are subject to Linux permissions (user, group, and mode bits):
$ ls -l /dev/sda
brw-rw---- 1 root disk 8, 0 Dec 12 10:00 /dev/sdaCommon patterns:
- Storage devices often belong to a group like
disk,plugdev, or distribution-specific groups. - Audio, video, and input devices might be owned by groups like
audio,video,input. - Ordinary users gain access through group membership, not by changing permissions on
/dev/*directly.
Do not run chmod or chown on /dev entries casually:
- Changes can break system behavior or open security holes.
- Many entries are recreated on reboot, so manual changes won’t persist.
If you need access to a device (e.g. USB serial adapter), the normal approach is:
- Check its permissions and group:
ls -l /dev/ttyUSB0- If appropriate, add your user to that group (which requires admin privileges and typically a logout/login to apply).
Symlinks and stable device names
Many /dev entries are symbolic links (symlinks) pointing to the “real” device node, especially for disks. For example:
$ ls -l /dev/disk/by-uuid
lrwxrwxrwx 1 root root 10 Dec 12 10:00 1234-ABCD -> ../../sda1Common subdirectories:
/dev/disk/by-uuid/— by filesystem UUID/dev/disk/by-label/— by filesystem label/dev/disk/by-id/— by hardware IDs/dev/disk/by-path/— by physical connection path
These provide stable names that don’t change if device order changes (e.g. when you plug in another drive). System configuration files often use these stable names rather than raw /dev/sdX device names.
As a beginner, you’ll most often encounter them indirectly in configuration files such as /etc/fstab (which is covered elsewhere).
Viewing device information safely
Here are some safe, read-only ways to inspect /dev and related information:
- List all devices:
ls -l /dev- Filter by type (character/block):
# Character devices
find /dev -maxdepth 1 -type c
# Block devices
find /dev -maxdepth 1 -type b- Show block devices and their hierarchy:
lsblk- Show udev-managed attributes for a device:
udevadm info --query=all --name=/dev/sdaThese commands let you explore without modifying anything.
Safety guidelines for beginners
Because /dev represents hardware and critical virtual devices, interact with it carefully:
- Avoid writing directly to devices (like
/dev/sda,/dev/nvme0n1) unless you absolutely know what you are doing—this can erase data or corrupt filesystems. - It is safe to:
- Read from devices like
/dev/null,/dev/zero,/dev/random,/dev/urandom(within reason). - Use
ls,lsblk, and similar tools to inspect devices. - Use higher-level tools (partition editors, disk utilities, file managers) instead of raw device writes for everyday tasks.
Understanding /dev gives you insight into how Linux exposes hardware and core system resources. As you move on to chapters about storage, mounting, system administration, and security, you’ll see /dev paths used frequently in real commands and configuration files.