Find Large Files in Linux

find large files in linux

Find Large files LinuxToday we will show you how you can find large files in Linux. One of the most common things you will do as a Linux system administrator is finding useless large files that consume disk space and removing them to free up space for applications that actually need it. Let’s dive in and find out how we can find large files in Linux.

Find the largest directories and files in Linux

First, we are going to look at how we can find the largest directories and files in Linux combined, execute the following command to find the top 10 largest directories and files on your Linux server:

# du -ah /* 2>/dev/null | sort -rh | head -n 10

The output should show you the largest directories and files:

3.2G    /backup
1.3G    /usr
1.1G    /var
922M    /home
713M    /var/lib
584M    /odoo
580M    /usr/lib
579M    /odoo/odoo-server
501M    /home/largefile3
404M    /odoo/odoo-server/addons

Find the top largest directories in Linux

This command can be pretty useful when you need to check the size of the directories in the root partition to get an idea of how the used space on your server is distributed. Using the following command you can find the top 10 largest directories in the root partition:

# du -sh /*/ 2>/dev/null | sort -rh | head -n 10

The output should show you the largest directories:

3.2G    /backup
1.3G    /usr/
1.1G    /var/
922M    /home/
584M    /odoo/
135M    /opt/
43M     /lib/
40M     /run/
30M     /root/
10M     /bin/

You can also use the following command to check the size of the sub-directories of a given directory, in this case, we’ll use the directory ‘var’:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
# find /var/* -type d -exec du -sh {} 2>/dev/null + | sort -rh | head -n 10

The output should list the sub-directories of the ‘var’ directory:

713M    /var/lib
357M    /var/cache
40M     /var/www
3.1M    /var/log
124K    /var/spool
52K     /var/backups
20K     /var/mail
12K     /var/tmp
4.0K    /var/opt
4.0K    /var/local

how to find large files in linuxFind the top largest files in Linux

Sometimes you may want to look for large files, especially large log files that can fill up your server pretty quickly, using the following command you can find the top 10 largest files on your server:

# find / -type f -exec du -sh {} 2>/dev/null + | sort -rh | head -n 10

The output should show you the largest files:

501M    /home/largefile3
257M    /home/largefile2
121M    /home/largefile1
111M    /odoo/odoo-server/.git/objects/pack/pack-dcf71f4c259beb18e9784d3b4a00a45e1f2a8382.pack
111M    /backup/odoo/odoo-server/.git/objects/pack/pack-dcf71f4c259beb18e9784d3b4a00a45e1f2a8382.pack
101M    /var/lib/mongodb/journal/WiredTigerPreplog.0000000002
101M    /var/lib/mongodb/journal/WiredTigerPreplog.0000000001
100M    /backup/var/lib/mongodb/journal/WiredTigerPreplog.0000000002
100M    /backup/var/lib/mongodb/journal/WiredTigerPreplog.0000000001
77M     /var/lib/mysql/ibdata1

Find the largest files with a specific extension in Linuxfinding large files in linux

If you are looking for large files of a particular extension you can find the top 10 largest files by their extension with the following command, we are going to use the ‘deb’ extension in this case:

# find / -type f -iname "*.deb" -exec du -sh {} + | sort -rh | head -10

The output should show you the largest files containing the extension we provided:

31M     /var/cache/apt/archives/mongodb-org-tools_3.2.14_amd64.deb
31M     /backup/var/cache/apt/archives/mongodb-org-tools_3.2.14_amd64.deb
27M     /var/cache/apt/archives/libpython2.7-dev_2.7.12-1ubuntu0~16.04.1_amd64.deb
27M     /backup/var/cache/apt/archives/libpython2.7-dev_2.7.12-1ubuntu0~16.04.1_amd64.deb
14M     /opt/wkhtmltox-0.12.1_linux-trusty-amd64.deb
14M     /backup/opt/wkhtmltox-0.12.1_linux-trusty-amd64.deb
9.6M    /var/cache/apt/archives/mongodb-org-server_3.2.14_amd64.deb
9.6M    /backup/var/cache/apt/archives/mongodb-org-server_3.2.14_amd64.deb
8.0M    /var/cache/apt/archives/g++-5_5.4.0-6ubuntu1~16.04.4_amd64.deb
8.0M    /backup/var/cache/apt/archives/g++-5_5.4.0-6ubuntu1~16.04.4_amd64.deb

linux find large files

If you use one of our VPS Hosting plans, you don’t have search for the largest directories and files yourself, you can simply ask our expert Linux admins to find the largest directories and files on your Linux based VPS for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to find large files in Linux, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks

1 thought on “Find Large Files in Linux”

  1. Very good – but consider adding a -mount example – to exclude mounts and simply search the hard disk. I am guessing you could just add -mount to all of your examples to keep thing local?

    Reply

Leave a Comment