When you run out of disk space in Linux, it is helpful to find the largest files & directories in your Linux system so that you can move/delete some of them. In this article, we will look at how to find largest files & directories in Linux using du command.
How to Find Largest Files & Directories in Linux
Here are the steps to find the largest files & directories in Linux.
Open terminal and run the following command to file the largest files & directories in a specific folder. Replace /dir/ with the path to your directory.
$ sudo du -a /dir/ | sort -n -r | head -n 20
For example, here’s how to list the biggest directories & files in /home/
$ sudo du -a /home/ | sort -n -r | head -n 20
The above command will list the top 20 biggest folders & files in /home/ directory.
The du command estimates the disk usage for each file & folder in /home/ directory. The sort command will sort du command’s output. Head command will only show the top 20 results of sort command’s output.
Also read : How to Run Linux Command in Background
If you want to get a list of the biggest folders & files on your disk, run the following command.
$ sudo du -a / | sort -n -r | head -n 20
If you only want to list the top 5 biggest files & folders update the number 20 to 5 as shown below.
$ sudo du -a / | sort -n -r | head -n 5
Once you find the largest files & folders occupying most space on your disk, you can remove them using rm -r or mv commands.
In this article, we have shown a simple ways to quickly get a list of the largest files & folders on your disk in Linux.
Also read : How to Show Commands with Date/Time in Linux