Knowing how to check directory sizes in Linux is essential for managing disk space and keeping your system organized. Linux provides several built-in tools and commands to analyze storage usage and identify which directories or files are consuming the most space. Whether you are managing a small workstation or a large server, understanding these commands can help optimize performance and prevent storage issues.
du
CommandThe du
(Disk Usage) command is the most common and powerful tool to check directory sizes. It reports the disk space used by files and directories.
To check the size of a specific directory, run:
du -sh /path/to/directory
Options explained:
-s
: Displays only the total size.-h
: Shows human-readable output (KB, MB, GB).Example:
du -sh /home/user/Documents
This command displays the total size of the “Documents” folder in an easy-to-read format.
To list the sizes of all subdirectories:
du -h --max-depth=1 /home/user
This displays the size of each folder within /home/user
, helping you locate large directories quickly.
If you want to see how much space is being used on the entire system, use:
df -h
The df
(Disk Filesystem) command shows mounted filesystems, their total size, used space, and available space. It’s ideal for an overview of disk capacity and helps prevent running out of storage on critical partitions.
To find the largest directories on your system, combine commands:
du -h /path | sort -hr | head -10
This lists the top 10 largest directories in descending order. It’s a quick way to pinpoint which folders are consuming the most disk space.
ncdu
CommandFor a more interactive way to analyze directory sizes, install ncdu (NCurses Disk Usage):
sudo apt install ncdu
Then run:
ncdu /path/to/directory
ncdu
opens a graphical, text-based interface in the terminal, allowing you to navigate through directories and delete unnecessary files directly from the interface.
ls
and du
CombinationYou can combine ls
and du
to analyze directories more effectively:
ls -lh
This lists files with their sizes in human-readable format. To combine both commands for more detailed output:
du -ch /path/to/directory/*
This shows the size of each file and a cumulative total at the end.
find
for Targeted Directory AnalysisIf you want to find all files over a certain size, use:
find /path -type f -size +100M -exec ls -lh {} \;
This locates files larger than 100 MB. It’s useful for cleaning up old backups or large media files that consume space unnecessarily.
System administrators often automate disk checks using cron jobs. For example, create a cron task that logs directory sizes daily:
0 2 * * * du -sh /var/www >> /var/log/disk_usage.log
This command runs every night at 2 a.m. and saves size data to a log file for tracking.
/var/www
./home
for multiple users./var
and /tmp
.Efficient disk management is crucial for keeping your Linux system stable and fast. Commands like du
, df
, and ncdu
help you analyze storage, identify large files, and clean up space when needed. By regularly checking directory sizes, you ensure that your system runs smoothly and storage usage stays under control.
Overview WhatsMyName is a free, community-driven OSINT tool designed to identify where a username exists…
Managing disk usage is a crucial task for Linux users and administrators alike. Understanding which…
Efficient disk space management is vital in Linux, especially for system administrators who manage servers…
Managing user accounts is a core responsibility for any Linux administrator. Whether you’re securing a…
Linux offers powerful command-line tools for system administrators to view and manage user accounts. Knowing…
User management is a critical aspect of Linux administration. Each user in a Linux system…