Fundamentals 5 min read

Mastering Linux /dev Special Files: null, full, zero, random, urandom & pts

This guide explains the various special file types under Linux's /dev directory, shows how to identify them with ls, and demonstrates practical uses of /dev/null, /dev/full, /dev/zero, /dev/random, /dev/urandom, and /dev/pts through concrete command‑line examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering Linux /dev Special Files: null, full, zero, random, urandom & pts

Linux treats everything as a file, and the /dev directory contains many special file types. The most common are:

Ordinary file

Directory (d)

Symbolic link (l)

Socket (s)

Block device (b)

Character device (c)

Pipe (p)

The leading character shown by ls -l indicates the file type; for example, a leading - denotes an ordinary file, while c denotes a character device.

/dev/null

/dev/null

acts as a black hole that discards any data written to it. It is useful for silencing unwanted output.

$ echo "shouwangxiansheng" > /dev/null

/dev/full

When reading, /dev/full returns an endless stream of NUL bytes. When writing, it immediately reports “No space left on device,” which helps simulate a full‑disk condition.

$ echo "bianchengzhuji" > /dev/full
-bash: echo: write error: No space left on device

/dev/zero

Similar to /dev/null, data written to /dev/zero is discarded, but reading from it produces an infinite stream of NUL bytes.

$ cat /dev/zero | od -x
0000000 0000 0000 0000 0000 0000 0000 0000 0000 0000

/dev/random

/dev/random

provides high‑quality random data, blocking when insufficient entropy is available. It is suitable for cryptographic purposes.

$ cat /dev/random | od -x
0000000 2b07 daac 42f4 e1fd fb62 2098 870e e0af ...

/dev/urandom

/dev/urandom

also generates random data but does not block; it is faster but slightly less random than /dev/random.

$ cat /dev/urandom | od -x
0547560 f43e 696 a8936 2b27 36c8 4446 2802 1d47 ...

/dev/pts

The /dev/pts directory holds pseudo‑terminal devices created for each remote login session (e.g., SSH, telnet). Writing to a specific /dev/pts/N file sends output to the corresponding terminal.

$ tty
/dev/pts/0
$ echo "hahahaha" > /dev/pts/0

These special files are invaluable for testing, debugging, and scripting in Linux environments.

Conclusion

While many more special files exist under /dev, the ones covered here are frequently used to simplify development and testing tasks.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxrandomNULLdevspecial-files
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.