How to Find What Is Taking Up Disk Space in Linux?
Categories
Popular Posts
To identify what is taking up disk space on your system, you can use various commands to analyze your file system. In this guide, we will explore several commands that can help you quickly find the largest files and directories.
Step 1: Using the df Command
The df command shows disk space usage. To display the information in a human-readable format, use the -h flag:
df -h
This will provide a list of file systems, showing the used and available space in gigabytes or megabytes.
Step 2: Using the du Command
The du command helps analyze which files and directories are taking up the most space. To see the total size of all files in a specific directory, use:
du -sh /path/to/directory
For more detailed information, such as the size of each folder, use the --max-depth option:
du -h --max-depth=1 /path/to/directory
Step 3: Using the ncdu Command
For a more interactive approach, use ncdu (Ncurses Disk Usage), which provides a text-based interface for analyzing disk usage:
sudo dnf install ncdu # For CentOS/RHEL
sudo apt install ncdu # For Ubuntu/Debian
Run the program to see which files and folders are using the most space:
ncdu /path/to/directory
Step 4: Finding Large Files with the find Command
You can use the find command to search for files larger than a specified size. For example, to find files larger than 100 MB:
find /path/to/directory -type f -size +100M
Step 5: Sorting Files by Size
To sort files by size, use the ls command with the -lhS flag, which will display files with the largest sizes first:
ls -lhS /path/to/directory
Conclusion
By using the df, du, ncdu, and find commands, you can quickly and effectively identify what is taking up disk space on your Linux system. This will help you manage your system resources better and free up necessary space.