Kahibaro
Discord Login Register

`/dev`

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`

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:

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

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:

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.

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:

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”
  # Discard standard output
  command > /dev/null
  # Discard both standard output and standard error
  command > /dev/null 2>&1
`/dev/zero` — infinite zero bytes
  # 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

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 | base64

Audio, input, and other hardware

Depending on your system, you’ll see several hardware-related entries:

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/sda

Common patterns:

Do not run chmod or chown on /dev entries casually:

If you need access to a device (e.g. USB serial adapter), the normal approach is:

  1. Check its permissions and group:
   ls -l /dev/ttyUSB0
  1. 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 -> ../../sda1

Common subdirectories:

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:

  ls -l /dev
  # Character devices
  find /dev -maxdepth 1 -type c
  # Block devices
  find /dev -maxdepth 1 -type b
  lsblk
  udevadm info --query=all --name=/dev/sda

These commands let you explore without modifying anything.

Safety guidelines for beginners

Because /dev represents hardware and critical virtual devices, interact with it carefully:

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.

Views: 16

Comments

Please login to add a comment.

Don't have an account? Register now!