Linux: Find Top 10 Largest Files

This post will guide you how to find top 10 largest files and directories in Linux. How do I list or find the largest files and directories on a Linux system. How to find the largest files in directory recursively in Linux.

Find Top 10 Largest Files


If you want to find the top 10 or 5 largest files in a given directory, you can use the following methods to achieve the result.Method1: Using the DU Command
Type the following command to find the top 10 files in /etc/ directory:

# du -a /etc/ | sort -nr | head -n 10

Outputs:

[root@osetc_x8664 ~]# du -a /etc/ | sort -nr | head -n 10
27492 /etc/
14880 /etc/selinux
14872 /etc/selinux/targeted
7312 /etc/selinux/targeted/policy
6840 /etc/udev
6832 /etc/udev/hwdb.bin
5672 /etc/selinux/targeted/modules/active
5672 /etc/selinux/targeted/modules
4832 /etc/selinux/targeted/modules/active/modules
3688 /etc/selinux/targeted/policy/policy.29

If you want to find the top 5 largest files in /etc directory, type:

# du -a /etc/ | sort -nr | head -n 5

Outputs:

[root@osetc_x8664 ~]# du -a /etc/ | sort -nr | head -n 5
27492 /etc/
14880 /etc/selinux
14872 /etc/selinux/targeted
7312 /etc/selinux/targeted/policy
6840 /etc/udev

If you want to display the above result in human readable format, just changing the above command as followss:

# du -hs /etc/* | sort -rh | head -5

Outputs:

[root@osetc_x8664 ~]# du -hs /etc/* | sort -rh | head -5
15M /etc/selinux
6.7M /etc/udev
1.5M /etc/pki
656K /etc/services
472K /etc/sysconfig

Method2: Using Find Command


If you want to find the top 10 largest files in a directory and its sub-directories, you can use the find command to achieve it.
Type the following command:

# find / -type f -print0 | xargs -0 du -h | sort -rh | head -n 10

Outputs:

[root@osetc_x8664 etc]# find /etc -type f -print0 | xargs -0 du -h | sort -rh | head -n 10
6.7M /etc/udev/hwdb.bin
3.7M /etc/selinux/targeted/policy/policy.29
3.6M /etc/selinux/targeted/policy/policy.31
1.3M /etc/selinux/targeted/contexts/files/file_contexts.bin
656K /etc/services
372K /etc/selinux/targeted/modules/active/file_contexts.template
360K /etc/selinux/targeted/modules/active/file_contexts
360K /etc/selinux/targeted/contexts/files/file_contexts
352K /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
264K /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

Or you can execute another find command to find the top 10 largest files in /etc/ directory and its sub-directories, type:

# find -type f -exec du -Sh {} + | sort -rh | head -n 10

 

You might also like:

Sidebar



back to top