Disk space is a critical resource in any computer system, and it’s no different in Linux. Regularly monitoring disk space usage is crucial to ensuring that your system runs smoothly and efficiently. Running out of disk space can result in performance issues, system crashes, or even data loss.
This article will guide you through the essential commands and tools to check disk space and manage files on a Linux system.
Basic Commands to Check Disk Space in Linux

Monitoring disk space is crucial to keep your Linux system running smoothly. By using simple commands like df
and du
, you can easily check space usage, prevent potential issues like system crashes, and identify areas where you can free up storage to maintain optimal performance.
Check Out | How to Use the Touch Command in Linux
df
Command to Check Disk Space
The df
command is one of the most basic and widely used commands to check disk space in Linux. It provides an overview of the file system’s disk space usage, showing available, used, and total space for each mounted file system.
- Usage:
df
This will give a basic output of disk usage for all mounted file systems.
- Common Options:
-h
: Human-readable format (shows sizes in KB, MB, GB).-T
: Shows the type of file system.--total
: Gives the total disk space used across all file systems.
- Example Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 10G 8G 55% /
/dev/sdb1 50G 35G 12G 75% /mnt/data
du
Command to Check Disk Space
Usage:
du
This command will show the disk usage of files and directories starting from the current directory.
- Common Options:
-sh
: Displays the total disk space used by the current directory in a human-readable format.-h
: Provides sizes in a human-readable format (KB, MB, GB).--max-depth=N
: Limits the depth of subdirectories displayed.
- Example Output:
1.0M ./Documents
512K ./Downloads
4.0M .
Checking Disk Usage by Directory
To manage your disk space effectively, it’s crucial to identify which directories consume the most space. The du
command can be used to check usage for specific directories.
For example, to check the usage of your home directory:
du -sh ~
If you’re interested in deeper insights into a particular folder, use the --max-depth
option to limit how many levels of subdirectories are shown:
du -h --max-depth=1 ~
Using ls
Command to Check File Sizes
The ls
command can also provide file size details, but it’s typically used for listing files and directories. By adding the -lh
option, you can view file sizes in a human-readable format.
- Usage:
ls -lh
This will show files along with their sizes in bytes, kilobytes, megabytes, etc.
- Example Output:
-rw-r--r-- 1 user user 1.5M May 12 09:23 large_file.txt
drwxr-xr-x 2 user user 4.0K May 11 13:02 folder
Advanced Disk Space Monitoring Tools
While basic commands like df
and du
are excellent for checking disk space usage; more advanced tools can offer deeper insights and greater control. These tools are particularly useful when managing larger systems or when you need real-time, interactive views of disk space. Advanced disk space monitoring tools such as ncdu
and iotop
provide more detailed, user-friendly, and efficient ways to analyze storage usage and track system performance. Let’s dive into these tools and explore their capabilities.
ncdu
(NCurses Disk Usage) Command
ncdu
is an interactive disk usage viewer that provides a more user-friendly way to explore disk space. Unlike du
, which outputs plain text, ncdu
allows you to navigate directories and see their sizes more intuitively.
- Installation:
sudo apt install ncdu
- Usage:
ncdu
This will launch an interactive session where you can browse through directories and identify space hogs. It’s a powerful tool for analyzing disk space.
iotop
Command
iotop
is a utility that allows you to monitor real-time disk I/O activity, helping you identify which processes are consuming the most disk resources.
- Installation:
sudo apt install iotop
- Usage:
sudo iotop
Identifying Large Files and Directories
Sometimes, a large file or directory may be hidden deep within your system. To find large files, you can use the find
command to locate files over a certain size.
For example, to find files larger than 100MB:
find / -type f -size +100M
You can also sort files by size using the du
command to make it easier to find large files within a directory:
du -ah | sort -rh | head -n 10
Conclusion
Regularly checking your disk space and keeping an eye on file usage is essential for maintaining a healthy and efficient Linux system. The combination of basic commands like df
and du
, along with advanced tools such as ncdu
and iotop
, allows you to effectively monitor your system’s storage. Don’t forget to check disk health periodically and clean up unnecessary files to prevent disk space from running out. By staying proactive, you can avoid performance issues and ensure that your Linux system runs smoothly for longer periods.