Skip to main content
All CollectionsSupplementary GuidesDomains, Web Servers, and BeyondWeb Servers
How to Find the Biggest Files and Directories in the Linux command line?
How to Find the Biggest Files and Directories in the Linux command line?
Rapyd Team avatar
Written by Rapyd Team
Updated over a week ago

Over time, files and directories accumulate on your Linux system, making it challenging to figure out which ones are taking up the most space. Using the command line, you can quickly identify these storage hogs and manage your disk space more effectively.

Introduction to Disk Space Management

Maintaining efficient disk space is crucial for the smooth operation of any system. Regularly identifying and managing large files and directories can prevent potential issues, such as system slowdowns or lack of storage.

The du Command

The du command, short for "disk usage," is a standard command used to estimate file and directory space usage. To find the size of a directory:

du -sh /path/to/directory

The -s option provides a summary for the specified directory, and -h makes the output human-readable. To list the sizes of all directories and sub-directories:

du -h /path/to/directory | sort -rh | head -n 10

This command lists the ten largest directories. The sort -rh sorts the results in human-readable format, and head -n 10 lists the top ten entries.

The find Command

The find command is useful for searching for files based on various criteria. To find files larger than a specific size:

find /path/to/search -type f -size +100M

This command finds all files larger than 100MB in the specified directory and its sub-directories.

The ncdu Utility

While not included in all Linux distributions by default, ncdu (NCurses Disk Usage) is a disk utility that provides a visual representation and is handy for analyzing disk usage. To install ncdu:

  • On Debian/Ubuntu: sudo apt install ncdu

  • On Red Hat/Fedora: sudo yum install ncdu

  • On Arch Linux: sudo pacman -S ncduTo use ncdu:

ncdu /path/to/directory

This will provide an interactive interface where you can navigate through directories and see their sizes.

Summary of Commands

  • du helps estimate file and directory space usage.

  • find searches for files based on specified criteria.

  • ncdu provides a visual representation of disk usage and can be installed if not already present on the system.

Conclusion

Being able to identify large files and directories efficiently is essential for effective disk space management. With the Linux command line, you have powerful tools at your disposal to ensure your system remains optimized and clutter-free. Regularly checking and cleaning up unnecessary large files can keep your system performing at its best.

Did this answer your question?