{"id":12609,"date":"2019-03-28T03:43:14","date_gmt":"2019-03-28T03:43:14","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12609"},"modified":"2019-03-28T03:43:14","modified_gmt":"2019-03-28T03:43:14","slug":"10-useful-du-disk-usage-commands-to-find-disk-usage-of-files-and-directories","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/10-useful-du-disk-usage-commands-to-find-disk-usage-of-files-and-directories\/","title":{"rendered":"10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories"},"content":{"rendered":"<p>The Linux \u201c<strong>du<\/strong>\u201d (<strong>Disk Usage<\/strong>) is a standard\u00a0<strong>Unix\/Linux<\/strong>\u00a0command, used to check the information of disk usage of files and directories on a machine. The\u00a0<strong>du<\/strong>\u00a0command has many parameter options that can be used to get the results in many formats. The\u00a0<strong>du<\/strong>\u00a0command also displays the files and directory sizes in a recursively manner.<\/p>\n<div id=\"attachment_2016\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/10-useful-du-disk-usage-commands-to-find-disk-usage-of-files-and-directories\/12-useful-du-commands\/\" rel=\"attachment wp-att-2016\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2016\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/12-Useful-du-commands-300x215.png\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/12-Useful-du-commands-300x215.png 300w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/01\/12-Useful-du-commands.png 442w\" alt=\"Check Disk Usage In Linux\" width=\"300\" height=\"215\" aria-describedby=\"caption-attachment-2016\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-2016\" class=\"wp-caption-text\">Check Disk Usage of Files and Folders In Linux<\/p>\n<\/div>\n<p>This article explains\u00a0<strong>10 useful \u201cdu\u201d commands<\/strong>\u00a0with their examples, that might helps you to find out the sizes of files and directories in Linux. The information provided in this article are taken from the man pages of\u00a0<strong>du<\/strong>command.<\/p>\n<p><strong>Read Also:<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/how-to-check-disk-space-in-linux\/\" target=\"_blank\" rel=\"noopener\">12 \u201cdf\u201d Command to Check Linux System Disk Space<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/agedu-track-disk-space-usage-in-linux\/\" target=\"_blank\" rel=\"noopener\">Agedu \u2013 A Useful Tool for Tracking Down Wasted Disk Space in Linux<\/a><\/li>\n<\/ol>\n<p>1. To find out the disk usage summary of a\u00a0<strong>\/home\/tecmint<\/strong>\u00a0directory tree and each of its sub directories. Enter the command as:<\/p>\n<pre>[root@tecmint]# du  \/home\/tecmint\r\n\r\n40      \/home\/tecmint\/downloads\r\n4       \/home\/tecmint\/.mozilla\/plugins\r\n4       \/home\/tecmint\/.mozilla\/extensions\r\n12      \/home\/tecmint\/.mozilla\r\n12      \/home\/tecmint\/.ssh\r\n689112  \/home\/tecmint\/Ubuntu-12.10\r\n689360  \/home\/tecmint<\/pre>\n<p>The output of the above command displays the number of disk blocks in the\u00a0<strong>\/home\/tecmint<\/strong>\u00a0directory along with its sub-directories.<\/p>\n<p>2. Using \u201c<strong>-h<\/strong>\u201d option with \u201c<strong>du<\/strong>\u201d command provides results in \u201c<strong>Human Readable Format<\/strong>\u201c. Means you can see sizes in\u00a0<strong>Bytes<\/strong>,\u00a0<strong>Kilobyte<\/strong>s,\u00a0<strong>Megabytes<\/strong>,\u00a0<strong>Gigabytes<\/strong>\u00a0etc.<\/p>\n<pre>[root@tecmint]# du -h \/home\/tecmint\r\n\r\n40K     \/home\/tecmint\/downloads\r\n4.0K    \/home\/tecmint\/.mozilla\/plugins\r\n4.0K    \/home\/tecmint\/.mozilla\/extensions\r\n12K     \/home\/tecmint\/.mozilla\r\n12K     \/home\/tecmint\/.ssh\r\n673M    \/home\/tecmint\/Ubuntu-12.10\r\n674M    \/home\/tecmint<\/pre>\n<p>3. To get the summary of a grand total disk usage size of an directory use the option \u201c<strong>-s<\/strong>\u201d as follows.<\/p>\n<pre>[root@tecmint]# du -sh \/home\/tecmint\r\n\r\n674M    \/home\/tecmint<\/pre>\n<p>4. Using \u201c<strong>-a<\/strong>\u201d flag with \u201c<strong>du<\/strong>\u201d command displays the disk usage of all the files and directories.<\/p>\n<pre>[root@tecmint]# du -a \/home\/tecmint\r\n\r\n4       \/home\/tecmint\/.bash_logout\r\n12      \/home\/tecmint\/downloads\/uploadprogress-1.0.3.1.tgz\r\n24      \/home\/tecmint\/downloads\/Phpfiles-org.tar.bz2\r\n40      \/home\/tecmint\/downloads\r\n12      \/home\/tecmint\/uploadprogress-1.0.3.1.tgz\r\n4       \/home\/tecmint\/.mozilla\/plugins\r\n4       \/home\/tecmint\/.mozilla\/extensions\r\n12      \/home\/tecmint\/.mozilla\r\n4       \/home\/tecmint\/.bashrc\r\n689108  \/home\/tecmint\/Ubuntu-12.10\/ubuntu-12.10-server-i386.iso\r\n689112  \/home\/tecmint\/Ubuntu-12.10\r\n689360  \/home\/tecmint<\/pre>\n<p>5. Using \u201c<strong>-a<\/strong>\u201d flag along with \u201c<strong>-h<\/strong>\u201d displays disk usage of all files and folders in human readeable format. The below output is more easy to understand as it shows the files in\u00a0<strong>Kilobytes<\/strong>,\u00a0<strong>Megabytes<\/strong>\u00a0etc.<\/p>\n<pre>[root@tecmint]# du -ah \/home\/tecmint\r\n\r\n4.0K    \/home\/tecmint\/.bash_logout\r\n12K     \/home\/tecmint\/downloads\/uploadprogress-1.0.3.1.tgz\r\n24K     \/home\/tecmint\/downloads\/Phpfiles-org.tar.bz2\r\n40K     \/home\/tecmint\/downloads\r\n12K     \/home\/tecmint\/uploadprogress-1.0.3.1.tgz\r\n4.0K    \/home\/tecmint\/.mozilla\/plugins\r\n4.0K    \/home\/tecmint\/.mozilla\/extensions\r\n12K     \/home\/tecmint\/.mozilla\r\n4.0K    \/home\/tecmint\/.bashrc\r\n673M    \/home\/tecmint\/Ubuntu-12.10\/ubuntu-12.10-server-i386.iso\r\n673M    \/home\/tecmint\/Ubuntu-12.10\r\n674M    \/home\/tecmint<\/pre>\n<p>6. Find out the disk usage of a directory tree with its subtress in\u00a0<strong>Kilobyte<\/strong>\u00a0blcoks. Use the \u201c<strong>-k<\/strong>\u201d (displays size in\u00a0<strong>1024<\/strong>\u00a0bytes units).<\/p>\n<pre>[root@tecmint]# du -k \/home\/tecmint\r\n40      \/home\/tecmint\/downloads\r\n4       \/home\/tecmint\/.mozilla\/plugins\r\n4       \/home\/tecmint\/.mozilla\/extensions\r\n12      \/home\/tecmint\/.mozilla\r\n12      \/home\/tecmint\/.ssh\r\n689112  \/home\/tecmint\/Ubuntu-12.10\r\n689360  \/home\/tecmint<\/pre>\n<p>7. To get the summary of disk usage of directory tree along with its subtrees in\u00a0<strong>Megabytes<\/strong>\u00a0(<strong>MB<\/strong>) only. Use the option \u201c<strong>-mh<\/strong>\u201d as follows. The \u201c<strong>-m<\/strong>\u201d flag counts the blocks in\u00a0<strong>MB<\/strong>\u00a0units and \u201c<strong>-h<\/strong>\u201d stands for human readable format.<\/p>\n<pre>[root@tecmint]# du -mh \/home\/tecmint\r\n\r\n40K     \/home\/tecmint\/downloads\r\n4.0K    \/home\/tecmint\/.mozilla\/plugins\r\n4.0K    \/home\/tecmint\/.mozilla\/extensions\r\n12K     \/home\/tecmint\/.mozilla\r\n12K     \/home\/tecmint\/.ssh\r\n673M    \/home\/tecmint\/Ubuntu-12.10\r\n674M    \/home\/tecmint<\/pre>\n<p>8. The \u201c<strong>-c<\/strong>\u201d flag provides a grand total usage disk space at the last line. If your directory taken\u00a0<strong>674MB<\/strong>\u00a0space, then the last last two line of the output would be.<\/p>\n<pre>[root@tecmint]# du -ch \/home\/tecmint\r\n\r\n40K     \/home\/tecmint\/downloads\r\n4.0K    \/home\/tecmint\/.mozilla\/plugins\r\n4.0K    \/home\/tecmint\/.mozilla\/extensions\r\n12K     \/home\/tecmint\/.mozilla\r\n12K     \/home\/tecmint\/.ssh\r\n673M    \/home\/tecmint\/Ubuntu-12.10\r\n<strong>674M    \/home\/tecmint<\/strong>\r\n<strong>674M    total\r\n<\/strong><\/pre>\n<p>9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that matches given pattern. The below command excludes the \u201c<strong>.txt<\/strong>\u201d files while calculating the total size of diretory. So, this way you can exclude any file formats by using flag \u201c<strong>-\u2013exclude<\/strong>\u201c. See the output there is no\u00a0<strong>txt<\/strong>files entry.<\/p>\n<pre>[root@tecmint]# du -ah --exclude=\"*.txt\" \/home\/tecmint\r\n\r\n4.0K    \/home\/tecmint\/.bash_logout\r\n12K     \/home\/tecmint\/downloads\/uploadprogress-1.0.3.1.tgz\r\n24K     \/home\/tecmint\/downloads\/Phpfiles-org.tar.bz2\r\n40K     \/home\/tecmint\/downloads\r\n12K     \/home\/tecmint\/uploadprogress-1.0.3.1.tgz\r\n4.0K    \/home\/tecmint\/.bash_history\r\n4.0K    \/home\/tecmint\/.bash_profile\r\n4.0K    \/home\/tecmint\/.mozilla\/plugins\r\n4.0K    \/home\/tecmint\/.mozilla\/extensions\r\n12K     \/home\/tecmint\/.mozilla\r\n4.0K    \/home\/tecmint\/.bashrc\r\n24K     \/home\/tecmint\/Phpfiles-org.tar.bz2\r\n4.0K    \/home\/tecmint\/geoipupdate.sh\r\n4.0K    \/home\/tecmint\/.zshrc\r\n120K    \/home\/tecmint\/goaccess-0.4.2.tar.gz.1\r\n673M    \/home\/tecmint\/Ubuntu-12.10\/ubuntu-12.10-server-i386.iso\r\n673M    \/home\/tecmint\/Ubuntu-12.10\r\n674M    \/home\/tecmint<\/pre>\n<p>10. Display the disk usage based on modification of time, use the flag \u201c<strong>\u2013time<\/strong>\u201d as shown below.<\/p>\n<pre>[root@tecmint]# du -ha --time \/home\/tecmint\r\n\r\n4.0K    2012-10-12 22:32        \/home\/tecmint\/.bash_logout\r\n12K     2013-01-19 18:48        \/home\/tecmint\/downloads\/uploadprogress-1.0.3.1.tgz\r\n24K     2013-01-19 18:48        \/home\/tecmint\/downloads\/Phpfiles-org.tar.bz2\r\n40K     2013-01-19 18:48        \/home\/tecmint\/downloads\r\n12K     2013-01-19 18:32        \/home\/tecmint\/uploadprogress-1.0.3.1.tgz\r\n4.0K    2012-10-13 00:11        \/home\/tecmint\/.bash_history\r\n4.0K    2012-10-12 22:32        \/home\/tecmint\/.bash_profile\r\n0       2013-01-19 18:32        \/home\/tecmint\/xyz.txt\r\n0       2013-01-19 18:32        \/home\/tecmint\/abc.txt\r\n4.0K    2012-10-12 22:32        \/home\/tecmint\/.mozilla\/plugins\r\n4.0K    2012-10-12 22:32        \/home\/tecmint\/.mozilla\/extensions\r\n12K     2012-10-12 22:32        \/home\/tecmint\/.mozilla\r\n4.0K    2012-10-12 22:32        \/home\/tecmint\/.bashrc\r\n24K     2013-01-19 18:32        \/home\/tecmint\/Phpfiles-org.tar.bz2\r\n4.0K    2013-01-19 18:32        \/home\/tecmint\/geoipupdate.sh\r\n4.0K    2012-10-12 22:32        \/home\/tecmint\/.zshrc\r\n120K    2013-01-19 18:32        \/home\/tecmint\/goaccess-0.4.2.tar.gz.1\r\n673M    2013-01-19 18:51        \/home\/tecmint\/Ubuntu-12.10\/ubuntu-12.10-server-i386.iso\r\n673M    2013-01-19 18:51        \/home\/tecmint\/Ubuntu-12.10\r\n674M    2013-01-19 18:52        \/home\/tecmint<\/pre>\n<p><strong>Read Also :<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/fdisk-commands-to-manage-linux-disk-partitions\/\" target=\"_blank\" rel=\"noopener\">10 fdisk Commands to Manage Linux Disk Partitions<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/how-to-check-disk-space-in-linux\/\" target=\"_blank\" rel=\"noopener\">12 Useful \u201cdf\u201d Commands to Check Disk Space in Linux<\/a><\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.tecmint.com\/check-linux-disk-usage-of-files-and-directories\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Linux \u201cdu\u201d (Disk Usage) is a standard\u00a0Unix\/Linux\u00a0command, used to check the information of disk usage of files and directories on a machine. The\u00a0du\u00a0command has many parameter options that can be used to get the results in many formats. The\u00a0du\u00a0command also displays the files and directory sizes in a recursively manner. Check Disk Usage of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/10-useful-du-disk-usage-commands-to-find-disk-usage-of-files-and-directories\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories&#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-12609","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\/12609","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=12609"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12609\/revisions"}],"predecessor-version":[{"id":12610,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12609\/revisions\/12610"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}