Linux Administrator

Find the Big Files Size in Linux CentOS/Fedora/RHEL

As Linux administrator, sometimes we need to know what files are eating up all our disk space. Similarly, we should be able to discover a particular directory location on file system such /var, /tmp, /opt and /home etc.

In this article I will show how you can find the big files size on Linux system.

Although, there is no any shortcut command to find out the top space consuming files on Linux system. However, We can use following three commands with pipes to do this.

  • du :- It estimates file space usage.
  • sort :- Sort lines of text files or given input data.
  • head :- Display first 10 files and output the first part of files.
  • find :- To search file.

Command Example to Find Big Files Size on Linux

1. Display the biggest directory 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. Display the largest folder including the sub-directory 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. Display the largest files including the sub-directory 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. 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. 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. 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
Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment