{"id":11371,"date":"2019-03-13T08:17:46","date_gmt":"2019-03-13T08:17:46","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11371"},"modified":"2019-03-13T08:17:46","modified_gmt":"2019-03-13T08:17:46","slug":"how-to-find-out-top-directories-and-files-disk-space-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/how-to-find-out-top-directories-and-files-disk-space-in-linux\/","title":{"rendered":"How to Find Out Top Directories and Files (Disk Space) in Linux"},"content":{"rendered":"<p>As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find the unnecessary junks and free up them from your hard disk.<\/p>\n<p>This brief tutorial describes how to find the largest files and folders in the Linux file system using\u00a0<code>du<\/code>\u00a0and\u00a0<code>find<\/code>command. If you want to learn more about these two commands, then head over to the following articles.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/check-linux-disk-usage-of-files-and-directories\/\" target=\"_blank\" rel=\"noopener\">Learn 10 Useful \u2018du\u2019 (Disk Usage) Commands in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/35-practical-examples-of-linux-find-command\/\" target=\"_blank\" rel=\"noopener\">Master the \u2018Find\u2019 Command with this 35 Practical Examples<\/a><\/li>\n<\/ol>\n<h3>How to Find Biggest Files and Directories in Linux<\/h3>\n<p>Run the following command to find out top biggest directories under\u00a0<code>\/home<\/code>\u00a0partition.<\/p>\n<pre># du -a \/home | sort -n -r | head -n 5\r\n<\/pre>\n<div id=\"attachment_18280\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Largest-Directories-in-Linux.gif\" rel=\"attachment wp-att-18280\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18280\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Largest-Directories-in-Linux.gif\" alt=\"Find Largest Directories in Linux\" width=\"668\" height=\"155\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find Largest Directories in Linux<\/p>\n<\/div>\n<p>The above command displays the biggest 5 directories of my\u00a0<strong>\/home<\/strong>\u00a0partition.<\/p>\n<h4>Find Largest Directories in Linux<\/h4>\n<p>If you want to display the biggest directories in the current working directory, run:<\/p>\n<pre># du -a | sort -n -r | head -n 5\r\n<\/pre>\n<div id=\"attachment_18281\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Larget-Directories-Only.gif\" rel=\"attachment wp-att-18281\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18281\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Larget-Directories-Only.gif\" alt=\"Find Biggest Directories Only\" width=\"673\" height=\"152\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find Biggest Directories Only<\/p>\n<\/div>\n<p>Let us break down the command and see what says each parameter.<\/p>\n<ol>\n<li><code>du<\/code>\u00a0command: Estimate file space usage.<\/li>\n<li><code>a<\/code>\u00a0: Displays all files and folders.<\/li>\n<li><code>sort<\/code>\u00a0command : Sort lines of text files.<\/li>\n<li><code>-n<\/code>\u00a0: Compare according to string numerical value.<\/li>\n<li><code>-r<\/code>\u00a0: Reverse the result of comparisons.<\/li>\n<li><code>head<\/code>\u00a0: Output the first part of files.<\/li>\n<li><code>-n<\/code>\u00a0: Print the first \u2018n\u2019 lines. (In our case, We displayed first 5 lines).<\/li>\n<\/ol>\n<p>Some of you would like to display the above result in human readable format. i.e you might want to display the largest files in\u00a0<strong>KB<\/strong>,\u00a0<strong>MB<\/strong>, or\u00a0<strong>GB<\/strong>.<\/p>\n<pre># du -hs * | sort -rh | head -5\r\n<\/pre>\n<div id=\"attachment_18282\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-Directory-Size.gif\" rel=\"attachment wp-att-18282\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18282\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-Directory-Size.gif\" alt=\"Find Top Directories Sizes in Linux\" width=\"660\" height=\"153\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find Top Directories Sizes in Linux<\/p>\n<\/div>\n<p>The above command will show the top directories, which are eating up more disk space. If you feel that some directories are not important, you can simply delete few sub-directories or delete the entire folder to free up some space.<\/p>\n<p>To display the largest folders\/files including the sub-directories, run:<\/p>\n<pre># du -Sh | sort -rh | head -5\r\n<\/pre>\n<div id=\"attachment_18285\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Largest-Folder-and-Sub-directories.gif\" rel=\"attachment wp-att-18285\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18285\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Largest-Folder-and-Sub-directories.gif\" alt=\"Find Largest Folder and Sub directories\" width=\"562\" height=\"149\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find Largest Folder and Sub directories<\/p>\n<\/div>\n<p>Find out the meaning of each options using in above command:<\/p>\n<ol>\n<li><code>du<\/code>\u00a0command: Estimate file space usage.<\/li>\n<li><code>-h<\/code>\u00a0: Print sizes in human readable format (e.g., 10MB).<\/li>\n<li><code>-S<\/code>\u00a0: Do not include size of subdirectories.<\/li>\n<li><code>-s<\/code>\u00a0: Display only a total for each argument.<\/li>\n<li><code>sort<\/code>\u00a0command : sort lines of text files.<\/li>\n<li><code>-r<\/code>\u00a0: Reverse the result of comparisons.<\/li>\n<li><code>-h<\/code>\u00a0: Compare human readable numbers (e.g., 2K, 1G).<\/li>\n<li><code>head<\/code>\u00a0: Output the first part of files.<\/li>\n<\/ol>\n<h3>Find Out Top File Sizes Only<\/h3>\n<p>If you want to display the biggest file sizes only, then run the following command:<\/p>\n<pre># find -type f -exec du -Sh {} + | sort -rh | head -n 5\r\n<\/pre>\n<div id=\"attachment_18287\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Sizes-in-Linux.gif\" rel=\"attachment wp-att-18287\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18287\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Sizes-in-Linux.gif\" sizes=\"auto, (max-width: 867px) 100vw, 867px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Sizes-in-Linux.gif 867w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Sizes-in-Linux-768x136.gif 768w\" alt=\"Find Top File Sizes in Linux\" width=\"867\" height=\"154\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find Top File Sizes in Linux<\/p>\n<\/div>\n<p>To find the largest files in a particular location, just include the path besides the\u00a0<code>find<\/code>\u00a0command:<\/p>\n<pre># find \/home\/tecmint\/Downloads\/ -type f -exec du -Sh {} + | sort -rh | head -n 5\r\nOR\r\n# find \/home\/tecmint\/Downloads\/ -type f -printf \"%s %p\\n\" | sort -rn | head -n 5\r\n<\/pre>\n<div id=\"attachment_18288\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Size-in-Specific-Location.gif\" rel=\"attachment wp-att-18288\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-18288\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Size-in-Specific-Location.gif\" sizes=\"auto, (max-width: 887px) 100vw, 887px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Size-in-Specific-Location.gif 887w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/01\/Find-Top-File-Size-in-Specific-Location-768x140.gif 768w\" alt=\"Find Top File Size in Specific Location\" width=\"887\" height=\"162\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Find Top File Size in Specific Location<\/p>\n<\/div>\n<p>The above command will display the largest file from\u00a0<code>\/home\/tecmint\/Downloads<\/code>\u00a0directory.<\/p>\n<p>That\u2019s all for now. Finding biggest files and folders is no big deal. Even a novice administrator can easily find them.\u00a0If you find this tutorial useful, please share on your social networks and support TecMint.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/find-top-large-directories-and-files-sizes-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a Linux administrator, you must periodically check which files and folders are consuming more disk space. It is very necessary to find the unnecessary junks and free up them from your hard disk. This brief tutorial describes how to find the largest files and folders in the Linux file system using\u00a0du\u00a0and\u00a0findcommand. If you want &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/how-to-find-out-top-directories-and-files-disk-space-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Find Out Top Directories and Files (Disk Space) in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11371","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11371"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11371\/revisions"}],"predecessor-version":[{"id":11377,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11371\/revisions\/11377"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}