Find the Largest Files or Folders
Find the Largest Files and Folders on Linux is one of the essential tasks for any Linux user or administrator. It is very important is keeping an eye on disk space usage. The du
command (short for disk usage) is an incredibly useful tool that helps analyze the size of files and directories. In this article, we’ll cover two common use cases: using du -skh *
to check the sizes of files and directories in the current folder, and du -ah /path/to/folder | sort -rh | head -n 10
to find the largest files or folders in a directory.
Command to list 10 Biggest Folders
du -ah /path/to/folder | sort -rh | head -n 10
When you need to identify the largest files or directories in a specific path, the combination of du
, sort
, and head
is incredibly useful. Here’s a breakdown of the command:
du -ah /path/to/folder
: Shows the size of all files and directories recursively within the specified folder in human-readable format.-a
: Includes files in the output, not just directories.-h
: Displays sizes in a human-readable format.
sort -rh
: Sorts the output by size in reverse order, showing the largest items first.-r
: Reverse order (largest to smallest).-h
: Sorts by human-readable sizes (KB, MB, GB).
head -n 10
: Limits the output to the top 10 largest files or directories.
Example Output:
7T /data/a/
3T /data/a/folder1
2T /data/a/folder2
1G /data/a/folder3
1G /data/a/folder4
When to Use du -ah /path/to/folder | sort -rh | head -n 10
This command is ideal for identifying large files or folders that are consuming a significant portion of your disk space. It’s especially useful for pinpointing storage hogs in larger directories, helping you prioritize what to clean up.
Understanding Disk Usage with du -skh *
du -skh * | sort -rh
The command du -skh *
is a quick way to check the disk usage of all items (files and directories) in your current folder. Here’s how it works:
du
: The disk usage command.-s
: Summarizes the total size of each file or directory instead of showing sizes for every subdirectory.-k
: Outputs the size in kilobytes.-h
: Makes the output more human-readable, showing sizes in KB, MB, or GB, depending on the file size.*
: Represents all files and directories in the current folder.sort -rh
: Sorts the output by size in reverse order, showing the largest items first.-r
: Reverse order (largest to smallest).-h
: Sorts by human-readable sizes (KB, MB, GB).
Example Output:
300M backup_file.tar.gz
4.5M project_folder
12K script.sh
This output shows that script.sh
takes up 12KB, project_folder
uses 4.5MB, and backup_file.tar.gz
occupies 300MB of space.
When to Use du -skh *
This command is perfect for getting a quick snapshot of how much space each file or directory in your current folder is using. It’s an ideal starting point when trying to clean up disk space.
More example how to use du
command you can find on the following link.
A very useful application for monitoring disk space is ncdu
. You can find out how it works on the link.
Find the Largest Files and Folders on Linux