How To Find Big Size Files In Linux Operating System

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space.

Low disk space can also affect server performance and sometimes cause critical processes such as backup job to fail.

This article shows how you can find big files size on Linux CentOS and RHEL.

Command Example to Find Big Files Size on Linux

1. How to display the biggest directories in /var/log and display the result in human readable format

# cd /var/log
# du -sh * | sort -rh | head -10
78M     nginx
14M     audit
1012K   dmesg.old
980K    messages-20170109
700K    messages-20160907
556K    anaconda
288K    messages-20161212
128K    wtmp
120K    httpd
96K     messages-20160929

2. To display the largest folders including the sub-directories for /var/log :

# du -Sh /var/log | sort -rh | head -10
78M     /var/log/nginx
14M     /var/log/audit
3.6M    /var/log
556K    /var/log/anaconda
120K    /var/log/httpd
68K     /var/log/tuned
56K     /var/log/mariadb
28K     /var/log/php-fpm
4.0K    /var/log/varnish
4.0K    /var/log/ppp

or

# du -Sh /var/log | sort -n -r | head -n 10
556K    /var/log/anaconda
120K    /var/log/httpd
78M     /var/log/nginx
68K     /var/log/tuned
56K     /var/log/mariadb
28K     /var/log/php-fpm
14M     /var/log/audit
4.0K    /var/log/varnish
4.0K    /var/log/ppp
4.0K    /var/log/dirsrv

3. To display the largest files including the sub-directories for /var/log :

# du -ah /var/log | sort -rh | head -10
96M     /var/log
78M     /var/log/nginx/ehowstuff.local.error.log-20160907
78M     /var/log/nginx
14M     /var/log/audit
6.1M    /var/log/audit/audit.log.2
6.1M    /var/log/audit/audit.log.1
1.8M    /var/log/audit/audit.log
1012K   /var/log/dmesg.old
980K    /var/log/messages-20170109
700K    /var/log/messages-20160907

4. To find the largest files in a particular location or directory for example /var/log :

# find /var/log -type f -exec du -Sh {} + | sort -rh | head -n 10
78M     /var/log/nginx/ehowstuff.local.error.log-20160907
6.1M    /var/log/audit/audit.log.2
6.1M    /var/log/audit/audit.log.1
1.8M    /var/log/audit/audit.log
1012K   /var/log/dmesg.old
980K    /var/log/messages-20170109
700K    /var/log/messages-20160907
288K    /var/log/messages-20161212
184K    /var/log/anaconda/anaconda.storage.log
152K    /var/log/nginx/ehowstuff.local.access.log-20160907.gz

5. To find the largest files (top 10) in a particular location or directory for example /var/log :

# find /var/log -printf '%s %p\n'|sort -nr|head
81440064 /var/log/nginx/ehowstuff.local.error.log-20160907
6291477 /var/log/audit/audit.log.2
6291467 /var/log/audit/audit.log.1
1823505 /var/log/audit/audit.log
1052691 /var/log/dmesg
1001793 /var/log/messages-20170109
709481 /var/log/messages-20160907
293738 /var/log/messages-20161212
292000 /var/log/lastlog
187757 /var/log/anaconda/anaconda.storage.log

6. To display the largest files(top 20) in a particular location or directory for example /var/log using ls command :

# ls -lSh | head -n20
total 3.7M
-rw-r--r--  1 root       root    1.1M Jan  9 21:52 dmesg
-rw-------  1 root       root    979K Jan  9 15:12 messages-20170109
-rw-------  1 root       root    693K Sep  7 03:21 messages-20160907
-rw-------  1 root       root    287K Dec 12 10:01 messages-20161212
-rw-r--r--. 1 root       root    286K Jan  9 22:03 lastlog
-rw-rw-r--. 1 root       utmp    125K Jan  9 22:03 wtmp
-rw-------  1 root       root     95K Sep 29 21:01 messages-20160929
-rw-r--r--  1 root       root     94K Jan  9 14:57 dmesg.old
-rw-------  1 root       root     81K Jan  9 22:07 messages
-rw-------  1 root       root     55K Sep  6 23:16 secure-20160907
-rw-r--r--  1 root       root     36K Sep  7 03:21 cron-20160907
-rw-------. 1 root       root     26K Jan  4 22:12 yum.log-20170109
-rw-r--r--  1 root       root     23K Jan  9 21:53 vmware-vmsvc.log
-rw-------. 1 root       root     17K Dec 30  2015 yum.log-20160101
-rw-------  1 root       root    9.3K Jan  9 14:59 secure-20170109
-rw-r--r--  1 root       root    9.2K Jan  9 21:52 boot.log
-rw-------. 1 root       root    8.0K Dec 20 22:39 grubby
-rw-------  1 root       root    7.3K Dec 12 10:17 maillog-20161212
-rw-r--r--  1 root       root    5.4K Jan  9 15:19 cron-20170109

Leave a Reply

Your email address will not be published. Required fields are marked *