A device file is a special entry in the file system that represents a hardware device or kernel service, so that programs can reach it through the same open, read, write and close calls they use for regular files. In operating systems derived from Unix, including Linux, the BSD family and macOS, device files usually live under /dev, and they are also called a device node or a special file.
Device files embody the Unix principle that everything is a file. Within the Drivers & devices layer of an operating system, they form the boundary between user space and a device driver: the file itself stores no data, only a pointer to the driver that will handle every operation on it.
How a device file connects programs to drivers
A device file is an inode whose type marks it as a device and which carries a major number and a minor number instead of data blocks. When a process opens it, the kernel uses the major number to select the driver and passes the minor number to that driver, which uses it to identify a specific unit, partition or channel.
After the open succeeds, the kernel routes system calls to the driver’s file operations table. A read on /dev/ttyS0 becomes a call into the serial driver, and an ioctl request carries device-specific commands that do not fit the byte-stream model, such as setting a baud rate or ejecting media.
The table below lists the attributes stored in a device file and what each controls.
| Attribute | Example | Purpose |
|---|---|---|
| File type | c or b in ls -l output | Marks a character or block device |
| Major number | 8 for SCSI disks on Linux | Identifies the responsible driver |
| Minor number | 1 for the first partition of sda | Identifies the unit or partition |
| Owner and group | root:disk | Controls who may open the device |
| Permission bits | 0660 | Grants read and write rights |
| Path name | /dev/sda1 | Stable name used by programs |
Character, block and pseudo device files
Device files fall into two kernel types: character devices and block devices. A character device transfers data as a stream of bytes without kernel buffering of fixed blocks, while a block device offers random access in fixed-size blocks through the page cache and an I/O scheduler, which suits storage.
Many device files correspond to no physical hardware at all. These pseudo devices expose kernel functions through the same interface, which makes them useful in scripts and testing. The comparison below summarizes the main categories.
| Category | Typical examples | Access model | Main use |
|---|---|---|---|
| Character device | /dev/ttyS0, /dev/input/event0 | Byte stream | Terminals, serial ports, input |
| Block device | /dev/sda, /dev/nvme0n1 | Fixed-size blocks | Disks and partitions |
| Pseudo device | /dev/null, /dev/zero, /dev/urandom | Byte stream | Discarding data, zeros, randomness |
| Virtual terminal | /dev/tty1, /dev/pts/0 | Byte stream | Consoles and terminal emulators |
| Loop device | /dev/loop0 | Fixed-size blocks | Mounting disk image files |
Some systems blur the distinction. FreeBSD removed block device files and exposes storage only as character devices, relying on the file system layer for caching, while Linux keeps both types and also offers raw access through flags such as O_DIRECT.
How device files are created and managed
Early Unix systems used a static `/dev` directory filled with nodes created by the mknod command or a MAKEDEV script, often thousands of entries for hardware that was never present. Modern systems create device files dynamically as devices appear during device enumeration and plug and play events.
- Linux mounts devtmpfs, where the kernel itself creates nodes, and the udev daemon (part of systemd) applies rules for permissions, ownership and persistent symbolic links such as
/dev/disk/by-uuid/. - FreeBSD uses devfs, a kernel file system that shows only existing devices and applies rules through
devfs.rules. - macOS also uses a devfs implementation, populated by the I/O Kit driver framework, with names such as
/dev/disk2s1.
Persistent names matter because kernel names such as sda and sdb depend on detection order and can change between boots. Configuration files like /etc/fstab should therefore reference UUIDs or labels rather than raw kernel names.
Device files compared with other device interfaces
Device files are not the only way an operating system exposes hardware. The table below compares them with related mechanisms so that the right interface can be chosen for a task.
| Interface | Platform | Typical content | Best suited for |
|---|---|---|---|
| Device file in /dev | Unix-like systems | Data path to a driver | Reading and writing device data |
| sysfs in /sys | Linux | Attributes and topology | Inspecting and configuring devices |
| procfs in /proc | Linux and others | Process and kernel state | Monitoring and diagnostics |
| Device object namespace | Windows | Named kernel objects such as \\.\PhysicalDrive0 | Opening devices with CreateFile |
| Memory-mapped I/O | All platforms | Device registers in address space | Driver-level hardware control |
Windows has no `/dev` directory, but its object manager plays a similar role: drivers create named device objects, and user programs open them through symbolic links in the \\.\ namespace. The concept is equivalent even though the file system does not show the entries.
Security risks and common mistakes
Because a device file grants direct access to hardware, its permissions are a security boundary. Write access to a raw disk node bypasses every file permission on the file systems it contains, and access to /dev/mem historically allowed reading kernel memory, which is why modern kernels restrict it.
| Problem | Cause | Remedy |
|---|---|---|
| Permission denied on a serial port | User not in the dialout group | Add the user to the group or write a udev rule |
Wrong disk overwritten by dd | Kernel names changed order | Verify with lsblk and use persistent names |
| Device node missing after boot | Driver not loaded or rule failed | Check dmesg and udev logs |
| Container sees host disks | Overly broad device access | Grant only specific devices to the container |
| Mounted file system allows device nodes | Missing nodev option | Mount untrusted media with nodev |
A common misconception is that deleting a device file removes the device. Removing the node only removes the name; the driver and hardware remain, and udev or devtmpfs will usually recreate the entry at the next event or boot.
In simple terms
A device file is like a labeled door in a hallway. Behind each door is not a room full of papers but a worker who handles a machine, such as a printer, a disk or a keyboard. Programs do not need to know how each machine works; they simply knock on the right door and hand over or collect data.
This is why so many tools work with hardware so easily. The same command that copies a normal file can copy data from a disk, because the device looks like a file from the outside.
A practical example
A system administrator needs to write a 4 GB Linux installer image to a USB stick on a laptop that also has an internal NVMe drive. Running lsblk shows the internal drive as /dev/nvme0n1 and the newly inserted 32 GB stick as /dev/sda, a block device created by udev seconds after insertion.
The administrator confirms the size and model, then runs dd with the image as input and /dev/sda as output, using a block size of 4 MB and the status=progress option. After about four minutes the copy finishes, sync flushes the remaining buffers, and the stick boots correctly on the target machine. Because the administrator verified the device file name before writing, the internal drive stayed untouched.