Quick Answer: The Best Linux Commands to Check Disk Space
If you need to quickly check disk space in Linux on a server or VPS, built-in utilities are sufficient. They allow you to check free space, directory sizes, inode usage, and quickly identify disk problems without installing additional software.
Basic Linux disk space commands:
- df -h — Shows file system usage and free space.
- du -sh /path — Displays the size of the selected directory.
- du -h --max-depth=1 — Helps find the largest folders.
- ncdu — An interactive disk usage analyzer.
- df -i — Checks inode usage.
- find — Finds large files.
- lsblk — Shows disks, partitions, and mount points.
- lsof +L1 — Finds deleted files that are still taking up space.
Why Disk Space Monitoring Matters on Linux Servers
Downtime, Failed Backups, and Database Errors
If Linux disk space is not monitored, the file system may unexpectedly become full. This leads to service interruptions, backup failures, and database errors.
Performance and Disk I/O Problems
Increasing Linux disk usage reduces performance even before the disk is completely full. Disk I/O load increases, processing of logs and temporary files slows down, which degrades service performance.
Security and Runaway Logs
Regular storage checking in Linux helps control the growth of files in /var/log. This prevents disk overflow, simplifies diagnostics, and speeds up the search for critical errors.
Linux Disk Space Basics: Filesystems, Mount Points and Inodes
To accurately analyze disk usage in Linux, it's important to understand the difference between a physical disk, partition, filesystem, and directory. When checking Linux disk space, users often expect to see the size of individual folders, but most system utilities work differently. For example, the df command shows usage at the filesystem level, not the size of a specific directory. If a partition is mounted under /var, the statistics will apply to the entire filesystem, not just the contents of a single folder.
When attempting to run Linux check disk size, it's important to consider mount points—the mount points through which partitions are accessible to the system. A single server can use multiple partitions and filesystems: for example, separate partitions for /home, /var, or backup storage. Therefore, Linux total disk size doesn't always refer to the total drive size; it more often refers to the available space of a specific mounted filesystem.
Important points to consider when diagnosing storage usage:
- filesystem and directory are not the same thing: df shows filesystem usage, not the size of an individual folder;
- mount points determine which partition a directory belongs to; for example, /var may be on a separate partition;
- having free gigabytes does not guarantee the ability to write new files;
- inode exhaustion occurs when available inodes run out, even if disk space remains;
- a large number of small files can completely exhaust inodes faster than free space on an SSD or HDD;
- you can check inode usage separately to rule out hidden filesystem problems.
Check Free Disk Space in Linux with df
Use df -h for Human-Readable Output
The df -h command displays disk usage in a convenient format (KB, MB, GB). This is one of the most popular Linux command-line tools for viewing disk space, allowing you to quickly assess used and free space.
- Filesystem — partition or device name;
- Size — total capacity;
- Used — used space;
- Avail — free space;
- Use% — percentage used;
- Mounted on — mount point.
Check a Specific Filesystem or Directory
The df -h /var command allows you to check a specific partition or directory. This approach helps analyze space usage for logs, user data, or the root file system.
- /var — logs and system data;
- /home — user files;
- / — root file system.
Check Filesystem Type with df -
The df -T command displays the file system type (ext4, xfs, tmpfs, and others). This helps better understand the storage structure and its operating features.
Check Inode Usage with df -i
The df -i command displays inode usage. Even if there is free space, a lack of it can cause errors, so checking free disk space is important in Linux.
Check Disk Usage by Folder with du
When your disk starts filling up quickly, simply checking filesystem usage with df isn't enough. The next step is to determine which directory is taking up space. For this, use the du utility, which displays the size of directories and helps quickly identify the source of the problem. If your goal is to check disk space by folder in Linux, du remains one of the most practical tools for server troubleshooting.
To check the size of a specific directory, use:
du -sh /var/log
This command displays the total size of the selected folder in human-readable format. It's especially useful for analyzing directories that often cause rapid increases in storage usage: /var/log, /tmp, /var/lib, or backup directories.
If you need to quickly view the usage of all folders in the current directory, use:
du -sh *
This command displays the total size of each file and subdirectory. This is a convenient way to understand where exactly disk usage by folder is increasing in Linux before diving into further analysis.
For a more detailed check of the directory structure, use:
du -h --max-depth=1 /var
This command displays the size of first-level folders within /var, allowing you to quickly determine what is taking up the most space—logs, cache, databases, or temporary files. This is one of the most convenient ways to show disk usage by directory in Linux without having to manually navigate to each folder.
To immediately sort the heaviest directories, use:
du -h --max-depth=1 | sort -hr
This combination helps you instantly see the largest directories at the top of the list and speeds up troubleshooting on a production server.
A practical drill-down typically looks like this:
- first, check filesystem usage with df -h;
- identify the problematic directory with du -h --max-depth=1 /;
- navigate to the large folder and run du -sh *;
- repeat the analysis one level deeper until the source of the storage growth is found;
- check directories such as /var/log, /tmp, /var/lib and backup storage separately if usage increases unusually quickly.
Find Large Files in Linux
Find Files Larger Than 1 GB
The find / -type f -size +1G command searches the entire filesystem for files larger than 1 GB. This helps Linux detect disk usage and quickly identify large archives, dumps, ISO images, or old backups.
Find Large Log Files
The find /var/log -type f -size +100M command finds large log files in the /var/log directory. This analysis simplifies Linux disk usage and helps identify logs that are quickly taking up space.
Find Old Backups, Archives, and Temporary Files
The du -ah /path | sort -rh | head -n 20 command displays the largest files and directories. This is a convenient way to view disk usage in Linux and find the data taking up the most space.
List Files by Size with ls -lhS
The ls -lhS command sorts files by size and helps you quickly find the largest ones. Before deleting files, it's recommended to first check the search results to avoid deleting important system data.
Use ncdu for Interactive Disk Usage Analysis
How to Install ncdu on Ubuntu, Debian, CentOS, and RHEL
ncdu is an interactive disk usage analyzer that simplifies Linux disk usage and checking disk usage in Linux. On Ubuntu and Debian, it is installed with apt install ncdu, and on CentOS and RHEL, with yum install ncdu or dnf install ncdu.
How to Scan a Directory with ncdu
The ncdu /var command analyzes the selected directory and displays the results in an interactive interface. This simplifies Linux disk usage analysis and helps you quickly find files that are wasting space.
- ncdu / — analyze the entire filesystem;
- ncdu /var — check logs;
- ncdu /home — analyze user files;
- arrow keys — navigate;
- d — delete files (use with caution).
When ncdu Is Better Than du
ncdu is more convenient than du when you need to quickly find large directories and understand disk usage patterns. This tool is especially useful on servers with large numbers of logs, backups, and nested directories.
Other Useful Linux Disk Space Commands
lsblk: List Disks, Partitions, and Mount Points
The lsblk command displays disks, partitions, and mount points in a tree view. It is suitable for the Linux tasks list disk space and view disk space, helping you quickly assess the storage structure.
stat: Inspect File Size and Metadata
The stat command displays file size, permissions, inodes, and other metadata. For Linux tasks like get disk size, it allows you to quickly obtain information about a specific file.
- file size;
- creation and modification times;
- inode number;
- permissions and owner.
pydf: Alternative Human-Readable df Output
pydf is an alternative to df with a more convenient data display. This tool simplifies Linux disk space viewing, especially on servers with a large number of file systems.
lsof +L1: Find Deleted Files Still Using Disk Space
The lsof +L1 command finds deleted files that continue to take up disk space while open by a process. It's useful for analyzing Linux disk usage and identifying the causes of low disk space.
- Find deleted logs;
- Detect hung processes;
- Diagnose hidden disk usage;
- Free up disk space after a process restart.
Common Reasons Linux Servers Run Out of Disk Space
Large or Unrotated Log Files
Large log files in /var/log are one of the main reasons for increased Linux disk space usage. Without log rotation, logs gradually fill up the disk, especially after crashes or excessive logging.
Backups Stored on the Same Server
Storing backups on the same server increases Linux storage usage. Old archives and dumps quickly take up space, so it's best to store backups separately.
Docker Images, Containers, and Logs
Unused Docker images, containers, volumes, and logs continue to take up space. Without regular cleanup, the /var/lib/docker directory can quickly fill up the disk.
Package Manager Cache
The package manager cache (/var/cache/apt, yum, dnf) increases Linux disk space usage over time. Clearing it allows you to free up space without uninstalling programs.
Database and Application Data
Databases, user downloads, and application data gradually increase Linux storage usage, especially in the /var/lib/mysql, /var/lib/postgresql, and /home directories.
Too Many Small Files and Inode Exhaustion
A large number of small files can lead to inode exhaustion even when there is free space. For diagnostic purposes, use the df -i command when analyzing Linux storage usage.
How to Safely Free Disk Space in Linux
What Is Usually Safe to Remove
After checking free space in Linux, you can delete files that are no longer in use.
The following files can be safely deleted:
- Old archives and backups;
- Package manager cache (apt, yum, dnf);
- Temporary files in /tmp;
- Old archive logs;
- Unused Docker images and stopped containers;
- Application cache.
What You Should Not Delete Without Checking
Before deleting, ensure that the files are not in use by the system. Incorrect actions can lead to crashes or data loss.
It is not recommended to delete:
- Database files;
- System libraries;
- Active logs;
- Unknown files in /etc;
- Mounted storage directories;
- Application work files.
How to Truncate a Live Log File
If the log is actively being used, it's safer to clear it with truncate -s 0 logfile.log than to delete the file. This frees up space without stopping the service and helps check available disk space on Linux.
How to Clean Package Cache
To clear the cache, use apt clean on Debian/Ubuntu or yum clean all and dnf clean all on RHEL-like systems. This helps quickly resolve Linux disk space checks.
How to Prevent the Same Issue from Recurring
To avoid disk refilling, set up monitoring, log rotation, automatic cache cleanup, and store backups separately. Also, regularly monitor Linux disk space usage, Docker, and inode usage.
Disk Space Troubleshooting Workflow for Linux Servers
- Run df -h. Start with the df -h command to have Linux check disk space, identify the partition that is full, and assess the situation.
- Identify Full Mount Point. Find the partition where space is running low. Most often, this is /, /var, /home, or a Docker repository. Then run Linux show disk usage for a detailed analysis.
- Run df -i. If there is space but files are not being created, check inode usage.
- Analyze Directory Size with du -h --max-depth=1. Identify the directories taking up the most space to continue checking available disk space.
- Drill Down Into Large Directories. Check large folders, backups, logs, cache, and user files.
- Find Large Files. Use find or ls -lhS to locate the largest files.
- Check Deleted Open Files with lsof +L1. Find deleted files that are still being held by processes and taking up space.
- Decide Safe Cleanup. Delete only safe data: cache, old logs, temporary files, and unused Docker objects.
- Configure Monitoring and Prevention. Configure monitoring, log rotation, and regularly check Linux show disk usage to prevent disk overflows.
Proactive Disk Space Monitoring for VPS and Dedicated Servers
In production environments, manual monitoring is insufficient, so Linux storage usage monitoring should be continuous and automated. The primary goal is to prevent disk space from filling up, not to mitigate the consequences.
For VPS and dedicated servers, it's convenient to use several alert levels: warning at around 80%, increased risk at around 90%, and critical at 95%. These values may vary, but they help you respond proactively to problems.
It's important to monitor not only overall disk space but also individual sources of growth:
- utilization by mount points;
- growth of /var/log and application logs;
- size of backups;
- Docker storage (images, containers, volumes);
- inode usage via df -i.
Particular attention should be paid to inodes, as insufficient inodes can block file creation even when there is free space.
For automation, you can use cron scripts with df -h or monitoring systems such as Prometheus Node Exporter, Grafana, Netdata, and Zabbix. Many dashboards also have built-in notifications.
Key monitoring elements:
- Warnings at 75-85% utilization;
- Critical notifications at 90-95% utilization;
- Inode monitoring;
- Data growth rate monitoring;
- Log and backup monitoring;
- Alerts for sudden spikes in disk usage.
Monitoring should be complemented by automation: setting up log rotation, cache cleaning, limiting Docker storage, and migrating backups to separate systems. This approach makes Linux storage usage more stable and predictable.
When to Upgrade Storage or Move to a Larger Server
At a certain point, simple cleanup stops solving the problem, and Linux disk space becomes a matter of scaling rather than file deletion. If databases, logs, Docker workloads, or media files are growing faster than they can be cleaned up, this indicates that the server's current resources are no longer sufficient.
If disk capacity is regularly filling up, this is no longer a random error, but a characteristic of the workload. In this situation, increasing Linux hard drive and disk space indicates the need for more suitable storage: a larger NVMe drive, a VPS, or a dedicated server with expanded resources.
Before scaling, it's important to determine the source of growth and the type of workload. Databases, Docker, CI/CD, and backups require different configurations, so it's better to tailor the infrastructure to specific needs rather than simply increasing disk capacity.
FAQ
What is the fastest way to check disk space in Linux?
The fastest way is the df -h command. It displays file system usage in a convenient format and helps quickly assess free space. It is a basic tool for Linux disk usage and initial diagnostics.
How do I find what's taking up space on a Linux server?
Use du -h --max-depth=1 / and find to find large directories and files. These commands help analyze Linux storage usage and determine the cause of disk space overflow.
Why does Linux disk space get full even after deleting files?
Deleted files, but still open by processes, can be the cause. Logs, Docker data, and cache also often take up space. The lsof +L1 command helps find such hidden files when analyzing Linux disk space.
What's the difference between df and du in Linux?
df shows overall filesystem usage, while du analyzes the size of individual directories and files. Together, they help check available disk space and find the source of the problem.
How can I prevent running out of disk space again?
Configure monitoring, log rotation, disk full notifications, cache cleaning, and Docker storage monitoring. It's also important to monitor inodes and data growth for stable Linux disk space usage.