{"id":6858,"date":"2017-01-17T23:42:55","date_gmt":"2017-01-17T15:42:55","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=6858"},"modified":"2023-06-24T20:44:14","modified_gmt":"2023-06-24T20:44:14","slug":"find-big-files-size-on-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/find-big-files-size-on-linux\/","title":{"rendered":"How to Find Big Files Size on Linux RHEL\/CentOS"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone wp-image-6875 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2017\/01\/How-to-Find-Big-Files-Size-on-Linux-RHEL-or-CentOS.jpg\" alt=\"Find Big Files Size\" width=\"1280\" height=\"905\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2017\/01\/How-to-Find-Big-Files-Size-on-Linux-RHEL-or-CentOS.jpg 1280w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2017\/01\/How-to-Find-Big-Files-Size-on-Linux-RHEL-or-CentOS-300x212.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2017\/01\/How-to-Find-Big-Files-Size-on-Linux-RHEL-or-CentOS-768x543.jpg 768w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2017\/01\/How-to-Find-Big-Files-Size-on-Linux-RHEL-or-CentOS-1024x724.jpg 1024w\" data-sizes=\"(max-width: 1280px) 100vw, 1280px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1280px; --smush-placeholder-aspect-ratio: 1280\/905;\" \/><\/p>\n<p>For Linux administrators, there are times when we need to identify the files that are consuming the most space on our Linux server, leading to low free space. This is crucial as low disk space can impact server performance and may cause critical processes, such as backup jobs, to fail. In this comprehensive guide, we will explore how you can identify large file sizes on Linux CentOS and RHEL.<\/p>\n<p>For a deeper understanding of Linux servers, you can visit our pages on <a href=\"https:\/\/webhostinggeeks.com\/best\/web-server\/\">best web servers<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a>. If you&#8217;re interested in different types of hosting, we also have articles on <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared hosting<\/a>.<\/p>\n<h2>Finding Large File Sizes on Linux<\/h2>\n<h3>Displaying the Largest Directories in \/var\/log<\/h3>\n<p>To display the largest directories in \/var\/log in a human-readable format, you can use the following commands:<\/p>\n<pre>\r\n# cd \/var\/log\r\n# du -sh * | sort -rh | head -10\r\n<\/pre>\n<p>This will display the top 10 directories in terms of size.<\/p>\n<pre># cd \/var\/log\r\n# du -sh * | sort -rh | head -10\r\n78M     nginx\r\n14M     audit\r\n1012K   dmesg.old\r\n980K    messages-20170109\r\n700K    messages-20160907\r\n556K    anaconda\r\n288K    messages-20161212\r\n128K    wtmp\r\n120K    httpd\r\n96K     messages-20160929\r\n<\/pre>\n<h3>Displaying the Largest Folders Including Sub-directories<\/h3>\n<p>To display the largest folders including their sub-directories for \/var\/log, use the following commands:<\/p>\n<pre>\r\n# du -Sh \/var\/log | sort -rh | head -10\r\n<\/pre>\n<p>This will display the top 10 folders, including sub-directories, sorted by size.<\/p>\n<pre># du -Sh \/var\/log | sort -rh | head -10\r\n78M     \/var\/log\/nginx\r\n14M     \/var\/log\/audit\r\n3.6M    \/var\/log\r\n556K    \/var\/log\/anaconda\r\n120K    \/var\/log\/httpd\r\n68K     \/var\/log\/tuned\r\n56K     \/var\/log\/mariadb\r\n28K     \/var\/log\/php-fpm\r\n4.0K    \/var\/log\/varnish\r\n4.0K    \/var\/log\/ppp\r\n<\/pre>\n<p>or <\/p>\n<pre># du -Sh \/var\/log | sort -n -r | head -n 10\r\n556K    \/var\/log\/anaconda\r\n120K    \/var\/log\/httpd\r\n78M     \/var\/log\/nginx\r\n68K     \/var\/log\/tuned\r\n56K     \/var\/log\/mariadb\r\n28K     \/var\/log\/php-fpm\r\n14M     \/var\/log\/audit\r\n4.0K    \/var\/log\/varnish\r\n4.0K    \/var\/log\/ppp\r\n4.0K    \/var\/log\/dirsrv\r\n<\/pre>\n<h3>Displaying the Largest Files Including Sub-directories<\/h3>\n<p>To display the largest files including their sub-directories for \/var\/log, use the following commands:<\/p>\n<pre>\r\n# du -ah \/var\/log | sort -rh | head -10\r\n<\/pre>\n<p>This will display the top 10 files, including those within sub-directories, sorted by size.<\/p>\n<pre># du -ah \/var\/log | sort -rh | head -10\r\n96M     \/var\/log\r\n78M     \/var\/log\/nginx\/ehowstuff.local.error.log-20160907\r\n78M     \/var\/log\/nginx\r\n14M     \/var\/log\/audit\r\n6.1M    \/var\/log\/audit\/audit.log.2\r\n6.1M    \/var\/log\/audit\/audit.log.1\r\n1.8M    \/var\/log\/audit\/audit.log\r\n1012K   \/var\/log\/dmesg.old\r\n980K    \/var\/log\/messages-20170109\r\n700K    \/var\/log\/messages-20160907\r\n<\/pre>\n<h3>Finding the Largest Files in a Specific Location<\/h3>\n<p>To find the largest files in a specific location or directory, for example \/var\/log, use the following commands:<\/p>\n<pre>\r\n# find \/var\/log -type f -exec du -Sh {} + | sort -rh | head -n 10\r\n<\/pre>\n<p>This will find and display the top 10 largest files in the specified location.<\/p>\n<pre># find \/var\/log -type f -exec du -Sh {} + | sort -rh | head -n 10\r\n78M     \/var\/log\/nginx\/ehowstuff.local.error.log-20160907\r\n6.1M    \/var\/log\/audit\/audit.log.2\r\n6.1M    \/var\/log\/audit\/audit.log.1\r\n1.8M    \/var\/log\/audit\/audit.log\r\n1012K   \/var\/log\/dmesg.old\r\n980K    \/var\/log\/messages-20170109\r\n700K    \/var\/log\/messages-20160907\r\n288K    \/var\/log\/messages-20161212\r\n184K    \/var\/log\/anaconda\/anaconda.storage.log\r\n152K    \/var\/log\/nginx\/ehowstuff.local.access.log-20160907.gz\r\n<\/pre>\n<h3>Finding the Largest Files (Top 10) in a Specific Location<\/h3>\n<p>To find the largest files (top 10) in a specific location or directory, for example \/var\/log, use the following commands:<\/p>\n<pre>\r\n# find \/var\/log -printf '%s %p\\\\n'|sort -nr|head\r\n<\/pre>\n<p>This will find and display the top 10 largest files in the specified location.<\/p>\n<pre># find \/var\/log -printf '%s %p\\n'|sort -nr|head\r\n81440064 \/var\/log\/nginx\/ehowstuff.local.error.log-20160907\r\n6291477 \/var\/log\/audit\/audit.log.2\r\n6291467 \/var\/log\/audit\/audit.log.1\r\n1823505 \/var\/log\/audit\/audit.log\r\n1052691 \/var\/log\/dmesg\r\n1001793 \/var\/log\/messages-20170109\r\n709481 \/var\/log\/messages-20160907\r\n293738 \/var\/log\/messages-20161212\r\n292000 \/var\/log\/lastlog\r\n187757 \/var\/log\/anaconda\/anaconda.storage.log\r\n<\/pre>\n<h3>Displaying the Largest Files (Top 20) Using ls Command<\/h3>\n<p>To display thelargest files (top 20) in a specific location or directory, for example \/var\/log, using the ls command, use the following commands:<\/p>\n<pre>\r\n# ls -lSh | head -n20\r\n<\/pre>\n<p>This will display the top 20 largest files in the specified location.<\/p>\n<pre># ls -lSh | head -n20\r\ntotal 3.7M\r\n-rw-r--r--  1 root       root    1.1M Jan  9 21:52 dmesg\r\n-rw-------  1 root       root    979K Jan  9 15:12 messages-20170109\r\n-rw-------  1 root       root    693K Sep  7 03:21 messages-20160907\r\n-rw-------  1 root       root    287K Dec 12 10:01 messages-20161212\r\n-rw-r--r--. 1 root       root    286K Jan  9 22:03 lastlog\r\n-rw-rw-r--. 1 root       utmp    125K Jan  9 22:03 wtmp\r\n-rw-------  1 root       root     95K Sep 29 21:01 messages-20160929\r\n-rw-r--r--  1 root       root     94K Jan  9 14:57 dmesg.old\r\n-rw-------  1 root       root     81K Jan  9 22:07 messages\r\n-rw-------  1 root       root     55K Sep  6 23:16 secure-20160907\r\n-rw-r--r--  1 root       root     36K Sep  7 03:21 cron-20160907\r\n-rw-------. 1 root       root     26K Jan  4 22:12 yum.log-20170109\r\n-rw-r--r--  1 root       root     23K Jan  9 21:53 vmware-vmsvc.log\r\n-rw-------. 1 root       root     17K Dec 30  2015 yum.log-20160101\r\n-rw-------  1 root       root    9.3K Jan  9 14:59 secure-20170109\r\n-rw-r--r--  1 root       root    9.2K Jan  9 21:52 boot.log\r\n-rw-------. 1 root       root    8.0K Dec 20 22:39 grubby\r\n-rw-------  1 root       root    7.3K Dec 12 10:17 maillog-20161212\r\n-rw-r--r--  1 root       root    5.4K Jan  9 15:19 cron-20170109\r\n<\/pre>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">cd \/var\/log<\/span> \u2013 Changes the current directory to \/var\/log<\/li>\n<li><span class=\"fw-bold\">du -sh *<\/span> \u2013 Estimates file and directory space usage<\/li>\n<li><span class=\"fw-bold\">sort -rh<\/span> \u2013 Sorts the results in reverse order<\/li>\n<li><span class=\"fw-bold\">head -10<\/span> \u2013 Outputs the first 10 lines<\/li>\n<li><span class=\"fw-bold\">du -Sh \/var\/log<\/span> \u2013 Estimates space usage including subdirectories<\/li>\n<li><span class=\"fw-bold\">du -ah \/var\/log<\/span> \u2013 Estimates space usage for all files<\/li>\n<li><span class=\"fw-bold\">find \/var\/log -type f -exec du -Sh {} +<\/span> \u2013 Finds files in a specific location<\/li>\n<li><span class=\"fw-bold\">find \/var\/log -printf &#8216;%s %p\\\\n&#8217;<\/span> \u2013 Finds files and prints their size and name<\/li>\n<li><span class=\"fw-bold\">ls -lSh<\/span> \u2013 Lists files with their size in human-readable format<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Understanding how to manage disk space is a vital skill for any Linux administrator. By learning how to identify large files and directories, you can ensure that your server maintains optimal performance and prevent critical processes from failing due to low disk space. This guide has provided you with several commands and techniques to find large files on Linux CentOS and RHEL.<\/p>\n<p>Remember, it&#8217;s not just about finding large files; it&#8217;s about understanding your server&#8217;s file system and how it&#8217;s being used. By regularly checking and managing your disk usage, you can prevent potential issues and ensure your server runs smoothly. For more insights and guides on managing servers, check out our other articles on <a href=\"https:\/\/webhostinggeeks.com\/best\/web-server\/\">best web servers<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a>.<\/p>\n<h2>FAQ<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What does the &#8216;du&#8217; command do in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;du&#8217; command, short for &#8216;disk usage&#8217;, is used in Linux to estimate file and directory space usage. It can be used with various options to display the sizes of files and directories in different formats and orders.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the purpose of the &#8216;sort&#8217; command in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;sort&#8217; command in Linux is used to sort the lines of text in a file. It can be used with various options to sort in reverse order (-r), sort numerically (-n), or sort by human-readable sizes (-h), among others.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What does the &#8216;head&#8217; command do in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;head&#8217; command in Linux is used to output the first part of files. By default, it outputs the first 10 lines of each file to standard output. With more than one file, it precedes each set of output with a header identifying the file name.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the purpose of the &#8216;find&#8217; command in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;find&#8217; command in Linux is a powerful tool that allows you to search for files and directories in a directory hierarchy based on a user-given expression and performs action on each matched file. It can search for files by name, owner, group, type, permissions, date, and other criteria.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What does the &#8216;ls&#8217; command do in Linux?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The &#8216;ls&#8217; command in Linux is used to list the contents of a directory. It can be used with various options to display the list in different formats and orders. For instance, &#8216;ls -lSh&#8217; lists files with their size in a human-readable format, sorted by size.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>For Linux administrators, there are times when we need to identify the files that are consuming the most space on our Linux server, leading to low free space. This is&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6875,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[996],"tags":[1536],"class_list":["post-6858","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=6858"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6858\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6875"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=6858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=6858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=6858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}