Device file
Device files in Unix‑like systems are special files that act as interfaces to device drivers. They live in the file system and let programs talk to hardware using the same basic read and write system calls as ordinary files, making programming simpler and I/O consistent across devices.
There are two main types:
- Character devices: provide unbuffered, direct access to hardware (for example, keyboards or serial ports). They are sometimes called raw devices.
- Block devices: provide buffered access to data in fixed-size blocks (such as hard disks). You can read or write blocks, but timing and buffering may be hidden from your program.
Device files are identified by a major number (the device driver) and a minor number (the specific device). The exact numbers are set differently in different operating systems.
Not all device files map to physical hardware. Some are pseudo-devices that provide system services, such as /dev/null, /dev/tty, or /dev/random.
Device files are usually found under /dev. Some systems use devfs (a kernel-managed filesystem) to automatically create and remove device nodes, while Linux now typically relies on a user-space system like udev. In chroot or container environments, each has its own /dev to isolate hardware access.
You can create device nodes manually with the mknod command, but many modern systems manage devices automatically, and manual creation may not work in all setups.
Naming in /dev uses prefixes to indicate device types (for example, sda1 for a disk partition). The exact names and conventions vary between Unix variants.
Older DOS/Windows also reserved certain device names like CON, PRN, and AUX for devices, which can cause confusion if used as ordinary file or folder names.
This page was last edited on 3 February 2026, at 02:24 (CET).