How to Find Biggest Files and Directories in Linux
Run given below command to find out top biggest directories inside the /home
partition.
[root@itmaddy ~]# du -a /home | sort -n -r | head -n 5
4319256 /home
4319240 /home/anaconda3
4303408 /home/anaconda3/pkgs
837364 /home/anaconda3/pkgs/mkl-2021.4.0-h06a4308_640
837248 /home/anaconda3/pkgs/mkl-2021.4.0-h06a4308_640/lib
The above command displays the biggest 5 directories of my /home partition.
if you want to display largest files in KB, MB, or GB.
du -hs /home | sort -rh | head -5
[root@itmaddy var]# du -hs /var/* | sort -rh | head -5
102M /var/lib
3.3M /var/log
612K /var/cache
16K /var/spool
8.0K /var/db
Above command shows top directories, which are eating up more disk space.
To display the largest folders/files including the sub-directories, run:
[root@itmaddy var]# du -Sh | sort -rh | head -5
97M ./lib/rpm
1.9M ./log/anaconda
804K ./log
600K ./log/audit
532K ./lib/yum/history
Find Out Top File Sizes Only
If want to display biggest file sizes only, then you can run the following command:
[root@itmaddy var]# find -type f -exec du -Sh {} + | sort -rh | head -n 5
92M ./lib/rpm/Packages
2.2M ./lib/rpm/Providename
1.4M ./log/anaconda/journal.log
1.4M ./lib/rpm/Basenames
600K ./log/audit/audit.log
If you want find the largest files in a particular location, just include the path beside the find command:
[root@itmaddy var]# find /home/ -type f -exec du -Sh {} + | sort -rh | head -n 5
201M /home/anaconda3/pkgs/dal-2021.5.1-h06a4308_803/lib/libonedal_dpc.so.1.1
177M /home/anaconda3/pkgs/dal-2021.5.1-h06a4308_803/lib/libonedal_core.so.1.1
143M /home/anaconda3/pkgs/mkl-2021.4.0-h06a4308_640.conda
99M /home/anaconda3/pkgs/libllvm11-11.1.0-h3826bc1_1/lib/libLLVM-11.so
79M /home/anaconda3/pkgs/qt-5.9.7-h5867ecd_1/lib/libQt5WebEngineCore.so.5.9.7
The above command displays the largest file from /home