Managing storage space is a critical task for any administrator to ensure system stability and performance.
Without enough room, your system might trigger a no space left on device error, which can halt database operations or prevent software updates. Checking disk space in Linux helps you monitor consumption across partitions and identify specific files or directories that are exhausting your resources.
This guide explains four practical methods to verify your storage levels using built-in terminal commands. Master these approaches to maintain effective control over your file system.
Table of Contents
Method 1: Using the du Command
The linux du command reveals actual disk consumption by calculating the physical space files occupy on a storage device. It is the best tool for investigating which directories are “space hogs.”
Run this command for basic usage: du -h filename
The -h flag is essential as it converts bytes into human-readable units like KB, MB, or GB. To check an entire directory and its subfolders, use the -s flag to get a total summary: du -sh /var/log
This provides an aggregate consumption total, accurately reflecting storage usage even when dealing with complex directory structures.
Method 2: Applying the df Command
While du checks directory usage, the df (disk free) command provides a high-level overview of your entire file system. it shows the total capacity, used space, and available room on all mounted partitions.
Use this syntax for a human-readable report: df -h
This is typically the first command used when troubleshooting storage issues, as it quickly identifies if your root (/) or home (/home) partitions are nearing 100% capacity. It ensures you have the necessary disk space needed for installation before starting large updates.
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
Method 3: Using the ls Command
The ls command is primarily used to list directory contents, but it also provides quick size information for individual files.
Run this command to view file details: ls -lh filename
The -l flag activates the long format, displaying permissions and owners, while the fifth column shows the file size. To identify the largest files in a folder, combine it with the -S flag: ls -lhS
This sorts the output from largest to smallest, making it easy to spot massive log files or archives. Note that ls reports “apparent size” rather than actual disk allocation.
Method 4: Searching with the find Command
The find command is an advanced tool that locates files matching specific size criteria across your entire system. This is invaluable for hunting down large files hidden deep within the directory tree.
To locate files larger than 100MB, use: find / -size +100M
You can even set ranges to find large files in Linux between specific thresholds, such as between 50MB and 100MB: find / -size +50M -size -100M.
This command searches recursively through directories and can be filtered by type (e.g., -type f for regular files) to provide a more focused result.
Understanding Apparent vs. Actual Size
Linux stores data in fixed blocks, usually 4KB each. This leads to two different ways of measuring size:
- Apparent Size: The actual number of bytes the data contains (shown by
ls). - Actual Size: The total amount of physical disk space the file occupies (shown by
du).
For example, a tiny 1-byte file will still occupy a full 4KB block on the disk. This difference is particularly noticeable with sparse files, which contain “holes” of empty data that do not consume physical storage but appear large in metadata.
Step-by-Step Process
- Open your terminal application.
- Run
df -hto see which partition is running low on space. - Navigate to the suspect directory using
cd. - Execute
du -sh * | sort -hto list all subdirectories ranked by their storage consumption. - Use
ls -lhSwithin the largest directories to find individual files to delete or compress.
Practical Tips
- Include Hidden Files: Use the
-aflag (e.g.,ls -la) to ensure you aren’t missing hidden configuration files that might be taking up space in home directories. - Check Exact Bytes: If you are writing a script, use
stat -c "%s" filenameto get the exact byte count without human-readable conversion. - Monitor /tmp: Remember that
/tmpis a world-writable space often used for temporary data; check it regularly to prevent it from filling up your root partition.
Summary Table
| Task | Recommended Command | Best For… |
|---|---|---|
| Check partition status | df -h | Viewing free space on all disks. |
| Directory totals | du -sh dirname | Checking how much space a folder uses. |
| Sort files by size | ls -lhS | Finding the biggest files in a folder. |
| Hunt for massive files | find / -size +500M | Finding large files system-wide. |
| Exact byte counts | stat -c "%s" file | Precise measurements for scripts. |
FAQs
What’s the quickest way to check disk space? Run df -h. It provides an immediate overview of all your drives and their current percentage of usage.
Why do du and ls show different file sizes? ls shows the “apparent size” (content), while du shows the “actual size” (block allocation). Sparse files and block-level storage defaults cause this discrepancy.
Can I check directory size recursively? Yes, du -sh directoryname will calculate the total consumption of that folder plus all of its subdirectories.
How do I find all large files on my system? Run find / -type f -size +100M to list every regular file larger than 100MB.
Related Posts




