How are devices represented in UNIX?

Dani AI

Generated

As and correctly pointed toward the visible device entries, the short visible story is only half the picture. Device nodes are userland-facing proxies; the kernel holds the actual device objects and drivers. Two practical pieces people often miss are how the kernel maps a node to a driver (major/minor) and how userspace (udev/devtmpfs) names and populates those proxies dynamically.

Major/minor numbers route a node to the correct driver (major) and to the specific instance (minor). The kernel publishes device topology and attributes in sysfs, and udev watches that to create device nodes and useful symlink trees (for example, stable disk naming under disk/by-*). That separation matters: changing a filename in the device directory does not change the driver or device state; it only changes how you access it.

Quick, practical inspection and recovery steps:

udevadm monitor --udev --environment
udevadm info --attribute-walk --name=/dev/<node>
sudo udevadm control --reload-rules && sudo udevadm trigger
sudo mknod /dev/<name> c|b <major> <minor>   # temporary only if udev fails
journalctl -k    # or dmesg to see kernel messages

If a node is missing or permissions are wrong, prefer fixing or adding a udev rule (persistent, safe) rather than repeatedly chown/chmod or creating nodes by hand.

Notes and cautions: tie udev events to kernel logs when diagnosing hardware/driver errors. Avoid raw writes to block devices unless you know the device (writing raw data can destroy filesystems). The above expands on points from , and by showing how to inspect, recreate, and make persistent fixes without repeating the basic “where” that earlier replies covered.

Recommended Answers

All 7 Replies

As far as I understand it, everything is treated as a file in Unix and Linux. Even devices and running processes.

Typically, the file-system entries for all connected hardware/devices can be found in the /dev directory (and its sub-directories). If you open up a terminal and cd to /dev and then use ls -a -l , you can see which files refer to which devices.

There are two types of devices, block and char. Block devices tend to be things like RAM and hard-drives and char devices are pretty much anything else.

I don't know much more than that myself atm, so I can't really elaborate further, but I hope this helps!

commented: Accurate and short. +8

Devices are represented in the file system under the /dev directory.

All devices wil ble listed in cd /dev/

ls -l will show you all the devices

How are devices represented in UNIX?

These are called block devices and their location are /dev/...

All devices, be they block devices (disc drives etc), character devices (serial devices, modems), or other (network ports, memory, etc) are all represented as special files in /dev/. For example, the "bit bucket" where you can put a command's output that you aren't interested in is /dev/null. If you want to erase a disc, you can read from /dev/zero and write to the physical device. For example, you have a thumb drive that you plug into the system (unmounted) that is registered as /dev/sdx. Then you can wipe the device with the command: dd if=/dev/zero of=/dev/sdx

Hi

Devices in UNIX are represented by files. These are special files located in the dev directory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.