Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Find the Total Size of All Files in a Directory on Linux
Finding the total size of all files in a directory is a common task for Linux system administrators and users who need to monitor disk usage and manage storage effectively. Linux provides several command-line tools and GUI applications to calculate directory sizes in various formats.
Understanding directory sizes helps users identify storage bottlenecks, clean up unnecessary files, and optimize system performance. This guide covers multiple methods to find the total size of directories on Linux systems.
Finding the Total Size Using Command-Line Tools
The du Command
The du (disk usage) command is the most commonly used tool for checking directory sizes. By default, it displays sizes in kilobytes and includes subdirectories.
du
830720 ./Information 166144 ./Images 996868 .
To get only the current directory size excluding subdirectories, use the -s (summarize) option:
du -s
996868 .
For human-readable output, use the -h option which displays sizes in KB, MB, or GB:
du -h du -sh
812M ./Information 163M ./Images 974M .
Advanced du Options:
Apparent size Shows actual file sizes rather than disk usage:
du -sh --apparent-size
Specific directory Check size of a particular directory:
du -sh ~/Documents
Exclude files Skip certain file types:
du -sch --exclude '*.log'
Limit depth Control subdirectory scanning levels:
du -hc --max-depth=1 du -d1 -hc
Sort by size Display largest directories first:
du -h --max-depth=1 | sort -hr
The ncdu Command
The ncdu (ncurses disk usage) command provides an interactive interface for browsing directory sizes. Install it first:
sudo apt install ncdu -y # Ubuntu/Debian sudo yum install ncdu # RedHat/CentOS
Run ncdu to get an interactive display:
ncdu
This displays a navigable interface where you can use arrow keys to browse directories and see real-time size information. You can specify a target directory:
ncdu /var
The tree Command
The tree command displays directory structures in a tree format with size information. Install if not available:
sudo apt install tree -y # Ubuntu/Debian sudo yum install tree # RedHat/CentOS
Display directories with sizes in human-readable format:
tree -dh
[4.0K] . ??? [4.0K] Images ??? [ 20K] Information
Combine tree with du functionality:
tree --du -h
Comparison of Command-Line Tools
| Tool | Best For | Key Features | Installation |
|---|---|---|---|
| du | Quick size checks | Built-in, many options, scriptable | Pre-installed |
| ncdu | Interactive browsing | Navigate directories, real-time sorting | Requires installation |
| tree | Visual hierarchy | Tree structure, combined with du | Usually requires installation |
GUI Tools for Directory Size Analysis
QDirStat
QDirStat is a Qt-based graphical tool that provides treemap visualization of directory sizes. It shows directories and files in a heat-map representation, making it easy to identify large files and directories.
sudo apt install qdirstat -y
Launch from terminal or applications menu:
qdirstat
FileLight
FileLight displays disk usage in an interactive pie chart format using concentric rings. This makes it easy to visualize which directories consume the most space.
sudo apt install filelight -y
Launch FileLight:
filelight
To scan a specific directory: Scan ? Scan folder ? Select target directory
Common Use Cases
System cleanup Identify large directories consuming disk space
Storage monitoring Regular checks of critical directories like /var, /home
Backup planning Determine space requirements before creating backups
Performance optimization Find directories causing slow file operations
Conclusion
Linux provides multiple tools for finding directory sizes, from the versatile du command for quick checks to interactive tools like ncdu and GUI applications like QDirStat. Choose the method that best fits your workflow command-line tools for scripting and automation, or GUI tools for visual analysis and exploration.
