{"id":8297,"date":"2021-03-20T14:07:09","date_gmt":"2021-03-20T11:07:09","guid":{"rendered":"https:\/\/kifarunix.com\/?p=8297"},"modified":"2024-03-19T18:44:53","modified_gmt":"2024-03-19T15:44:53","slug":"check-directory-usage-with-du-command-in-linux","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/check-directory-usage-with-du-command-in-linux\/","title":{"rendered":"Check directory usage with du Command in Linux"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to check directory usage with <code>du<\/code> command in Linux. <code><strong>du<\/strong><\/code>, an acronym for <code><strong>disk usage<\/strong><\/code> can help you as a <strong>Linux Users or an administrator<\/strong> to check and report which files or directories are consuming how much disk space in the Linux system.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code> du [OPTION]... [FILE]...<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Checking directory usage with du Command in Linux<\/h2>\n\n\n\n<p>Examples outlined below shows how to use DU command to check directory usage in Linux<\/p>\n\n\n\n<p>1.  <strong>Reports the disk space for the current directory<\/strong><\/p>\n\n\n\n<p>Launch your terminal with<code> Ctrl+Alt+T<\/code> keys and type <code>du<\/code>. With no arguments, <code>du<\/code> reports the disk space for the current directory. Normally the disk space is printed in units of 1024 bytes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>12984\t.\/.mozilla\/firefox\/cxbch2t5.default-release-1615898171711\n4\t.\/.mozilla\/firefox\/Pending Pings\n4\t.\/.mozilla\/firefox\/Crash Reports\/events\n20\t.\/.mozilla\/firefox\/Crash Reports\n8\t.\/.mozilla\/firefox\/8jpgnpf9.default\n13028\t.\/.mozilla\/firefox\n4\t.\/.mozilla\/extensions\n13040\t.\/.mozilla\n85586428\t.<\/code><\/pre>\n\n\n\n<p>2. <strong>To display the disk usage of all files and directories<\/strong><\/p>\n\n\n\n<p>Use <code>-a<\/code> flag.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -a ~\/Downloads<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>9832\t\/home\/frank\/Downloads\/25 Days of Christmas Writeup (Blurred).pdf\n38800\t\/home\/frank\/Downloads\/vagrant_2.2.14_x86_64.deb\n588\t\/home\/frank\/Downloads\/HOW TO CREATE USERS AND COMPUTER VIA GROUP POLICY.pdf\n152756\t\/home\/frank\/Downloads\/xampp-linux-x64-7.4.11-0-installer.run\n201980\t\/home\/frank\/Downloads<\/code><\/pre>\n\n\n\n<p>3.<strong> Display disk usage of files in Human Readable Format<\/strong><\/p>\n\n\n\n<p>Using <code>-h<\/code> flag it displays sizes of files in:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>Bytes<\/em><\/strong><\/li>\n\n\n\n<li><strong><em>Kilobytes<\/em><\/strong><\/li>\n\n\n\n<li><strong><em>Megabytes<\/em><\/strong><\/li>\n\n\n\n<li><em><strong>Gigabytes<\/strong><\/em>, etc.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -h ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>64K\t\/home\/frank\/.mozilla\/firefox\/cxbch2t5.default-release-1615898171711\/storage\/default\n588K\t\/home\/frank\/.mozilla\/firefox\/cxbch2t5.default-release-1615898171711\/storage\n13M\t\/home\/frank\/.mozilla\/firefox\/cxbch2t5.default-release-1615898171711\n4.0K\t\/home\/frank\/.mozilla\/firefox\/Pending Pings\n4.0K\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\/events\n20K\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\n8.0K\t\/home\/frank\/.mozilla\/firefox\/8jpgnpf9.default\n13M\t\/home\/frank\/.mozilla\/firefox\n4.0K\t\/home\/frank\/.mozilla\/extensions\n13M\t\/home\/frank\/.mozilla\n82G\t\/home\/frank<\/code><\/pre>\n\n\n\n<p>4. <strong>Display total summary of disk usage size of a directory<\/strong><\/p>\n\n\n\n<p>Use<code> -s<\/code> flag<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -sh ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>82G\t\/home\/frank<\/code><\/pre>\n\n\n\n<p>5.<strong> Display disk usage of a directory in Kilobyte blocks<\/strong><\/p>\n\n\n\n<p>Use <code>-k<\/code> flag to print sizes in 1024-byte blocks. This option is equivalent to <code>--block-size=1K<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -k ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>64\t\/home\/frank\/.mozilla\/firefox\/cxbch2t5.default-release-1615898171711\/storage\/default\n588\t\/home\/frank\/.mozilla\/firefox\/cxbch2t5.default-release-1615898171711\/storage\n12984\t\/home\/frank\/.mozilla\/firefox\/cxbch2t5.default-release-1615898171711\n4\t\/home\/frank\/.mozilla\/firefox\/Pending Pings\n4\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\/events\n20\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\n8\t\/home\/frank\/.mozilla\/firefox\/8jpgnpf9.default\n13028\t\/home\/frank\/.mozilla\/firefox\n4\t\/home\/frank\/.mozilla\/extensions\n13040\t\/home\/frank\/.mozilla\n85591540\t\/home\/frank<\/code><\/pre>\n\n\n\n<p>6. <strong>Display disk usage of a directory in Megabytes blocks<\/strong><\/p>\n\n\n\n<p>Use <code>-m<\/code> flag print sizes in 1,048,576-byte blocks. This option is equivalent to <code>--block-size=1M<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -m ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>1\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\/events\n1\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\n1\t\/home\/frank\/.mozilla\/firefox\/8jpgnpf9.default\n13\t\/home\/frank\/.mozilla\/firefox\n1\t\/home\/frank\/.mozilla\/extensions\n13\t\/home\/frank\/.mozilla\n83587\t\/home\/frank<\/code><\/pre>\n\n\n\n<p>7. <strong>Print disk usage based on modification time of files<\/strong><\/p>\n\n\n\n<p>Use <code>--time<\/code> flag. It show the most recent modification timestamp (mtime) of any file in<br>the directory, or any of its subdirectories.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du --time ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>4\t2020-09-01 21:38\t\/home\/frank\/.mozilla\/firefox\/Pending Pings\n4\t2020-09-01 21:38\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\/events\n20\t2020-12-20 12:17\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\n8\t2020-09-01 21:38\t\/home\/frank\/.mozilla\/firefox\/8jpgnpf9.default\n13028\t2021-03-16 15:37\t\/home\/frank\/.mozilla\/firefox\n4\t2020-09-01 21:38\t\/home\/frank\/.mozilla\/extensions\n13040\t2021-03-16 15:37\t\/home\/frank\/.mozilla\n85593576 2021-03-18 15:19\t\/home\/frank<\/code><\/pre>\n\n\n\n<p>8. <strong>To find out the total disk usage of a given set of files or directories<\/strong><\/p>\n\n\n\n<p>Use <code>-c<\/code> or <code>--total<\/code> flag to print a grand total of all arguments after all arguments have been<br>processed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -ch ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du --total -h ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>20K\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\n8.0K\t\/home\/frank\/.mozilla\/firefox\/8jpgnpf9.default\n13M\t\/home\/frank\/.mozilla\/firefox\n4.0K\t\/home\/frank\/.mozilla\/extensions\n13M\t\/home\/frank\/.mozilla\n82G\t\/home\/frank\n<strong>82G\ttotal<\/strong><\/code><\/pre>\n\n\n\n<p><strong>9. Displays the disk usage of all files and directories, but excludes the files that matches given pattern<\/strong><\/p>\n\n\n\n<p>Use <code>--exclude=PATTERN<\/code> flag, this will skip subdirectories or files matching <code>PATTERN<\/code>. For example, <code>du --exclude=\"*.mozilla\" <\/code>~\/ excludes files whose names start or end in <code>.mozilla<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du --exclude=\"*.mozilla\" ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>11572\t\/home\/frank\/.cache\/google-chrome\/Profile 4\/Code Cache\/js\n11576\t\/home\/frank\/.cache\/google-chrome\/Profile 4\/Code Cache\n27648\t\/home\/frank\/.cache\/google-chrome\/Profile 4\n27652\t\/home\/frank\/.cache\/google-chrome\n33948\t\/home\/frank\/.cache\n85580720\t\/home\/frank<\/code><\/pre>\n\n\n\n<p> 10. <strong>Displays the disk usage of all files and directories, but excludes the files in the current directory<\/strong><\/p>\n\n\n\n<p>Use <code>--exclude-from=FILE<\/code> flag. Like <code>--exclude<\/code>, except take the patterns to exclude from FILE, one per line.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -cha ~\/Downloads<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>9.7M\t.\/25 Days of Christmas Writeup (Blurred).pdf\n38M\t.\/vagrant_2.2.14_x86_64.deb\n588K\t.\/HOW TO CREATE USERS AND COMPUTER VIA GROUP POLICY.pdf\n150M\t.\/xampp-linux-x64-7.4.11-0-installer.run\n198M\t.\n198M\ttotal<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -cha --exclude=xampp-linux-x64-7.4.11-0-installer.run<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>9.7M\t.\/25 Days of Christmas Writeup (Blurred).pdf\n38M\t.\/vagrant_2.2.14_x86_64.deb\n588K\t.\/HOW TO CREATE USERS AND COMPUTER VIA GROUP POLICY.pdf\n49M\t.\n49M\ttotal<\/code><\/pre>\n\n\n\n<p>In the above example i used Downloads to be my current directory. and we have seen that <code>xampp-linux-x64-7.4.11-0-installer.run<\/code> file has been excluded in the above output.<\/p>\n\n\n\n<p>11. <strong>List inode usage information instead of block usage<\/strong><\/p>\n\n\n\n<p>Use<code> --inodes<\/code> flag. This option is useful for finding directories which contain many files, and therefore eat up most of the inodes space of a file system.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du --inodes ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>5\t\/home\/frank\/.mozilla\/firefox\/Crash Reports\n2\t\/home\/frank\/.mozilla\/firefox\/8jpgnpf9.default\n91\t\/home\/frank\/.mozilla\/firefox\n1\t\/home\/frank\/.mozilla\/extensions\n94\t\/home\/frank\/.mozilla\n17412\t\/home\/frank<\/code><\/pre>\n\n\n\n<p>12.<strong> Finding the depth-ness of a directory<\/strong><\/p>\n\n\n\n<p>Use<code> -d DEPTH<\/code> or <code>--max-depth=DEPTH<\/code> to show the total for each directory (and file if \u2013all) that is at most <code>MAX_DEPTH<\/code> levels down from the root of the hierarchy.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -d0 ~\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>85604412\t\/home\/frank<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>du -h --max-depth=2 \/home\/frank<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>3.7M\t\/home\/frank\/.cache\/tracker\n37M\t\/home\/frank\/.cache\/google-chrome\n44M\t\/home\/frank\/.cache\n4.0K\t\/home\/frank\/.mozilla\/systemextensionsdev\n13M\t\/home\/frank\/.mozilla\/firefox\n4.0K\t\/home\/frank\/.mozilla\/extensions\n13M\t\/home\/frank\/.mozilla\n82G\t\/home\/frank<\/code><\/pre>\n\n\n\n<p>You can now use <code>du<\/code> command in Linux perfectly.<\/p>\n\n\n\n<p>For further understanding of du command, feel free to check:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>man du<\/strong><\/code><\/pre>\n\n\n\n<p>or<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>info du<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-use-htop-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">How to use htop Command in Linux<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/example-usage-of-ps-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Example Usage of ps Command in Linux<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/example-usage-of-ls-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Example Usage of ls Command in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to check directory usage with du command in Linux. du, an acronym for disk usage can help you<\/p>\n","protected":false},"author":6,"featured_media":8333,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[49,121],"tags":[3295,3296,3297,3291,3293,3292,3294],"class_list":["post-8297","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-cheatsheets","category-howtos","tag-centos-du-command","tag-directory-usage-in-linux","tag-disk-uage-command","tag-du-command","tag-how-to-use-du-command-linux","tag-linux-du-command","tag-ubuntu-du-command","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8297"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=8297"}],"version-history":[{"count":13,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8297\/revisions"}],"predecessor-version":[{"id":21894,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8297\/revisions\/21894"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/8333"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=8297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=8297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=8297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}