WittCode💻

No Space Left!

By

Learn what /dev/full is, does, its practical applications, and how you can use it in real-world scenarios.

Table of Contents 📖

/dev/full

Linux has several special device files inside /dev, each serving a unique purpose. One of the more intriguing ones is /dev/full, a device that always behaves as if the system has run out of disk space. Writing to /dev/full results in an "No space left on device" (ENOSPC) error.

INFO: Essentially, /dev/full is a simulated "disk full" scenario without needing an actual full disk.

echo "Hello, Linux!" > /dev/full
-bash: echo: write error: No space left on device

This behavior makes /dev/full useful for testing how programs handle disk space exhaustion. Appending data also fails:

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

Practical Use Case

Many applications need to handle low-storage conditions gracefully. You can use /dev/full to test how your application or script reacts when it can't write to a file. Imagine a program that logs messages to a file. If your program properly handles this error, it should log the issue elsewhere or stop writing. If not, it might crash. Consider the script below:

#!/bin/bash

echo "Writing data..." > /dev/full
if [ $? -ne 0 ]; then
    echo "Error: Disk is full!" >&2
fi
  • $? stores the exit status of the last executed command (echo "Writing data..." > /dev/full).
  • -ne means "not equal to", so this condition checks if the exit status is not 0 (indicating failure).
  • &2 redirects the output to stderr instead of stdout, which is useful for error messages.