{"id":279,"date":"2023-01-24T07:03:36","date_gmt":"2023-01-24T07:03:36","guid":{"rendered":"https:\/\/www.dedicatedcore.com\/blog\/?p=279"},"modified":"2025-05-23T06:38:31","modified_gmt":"2025-05-23T06:38:31","slug":"get-size-directory-linux","status":"publish","type":"post","link":"https:\/\/www.dedicatedcore.com\/blog\/get-size-directory-linux\/","title":{"rendered":"How to Get\/Find Size of Directory in Linux"},"content":{"rendered":"<p>Linux is frequently run using the command line. However, Linux&#8217;s command line, also referred to as the terminal, lacks an easy-to-use interface for checking disc space. We&#8217;ll look at various approaches to finding a directory&#8217;s size in Linux. Understanding how directories use disc space can help you allocate resources more effectively, spot storage bottlenecks, and manage your Linux system more efficiently. To <a href=\"https:\/\/www.dedicatedcore.com\/blog\/create-directory-linux-mkdir-command\/\" target=\"_blank\" rel=\"noopener\">organize and manage files<\/a>, one needs to create directories through the mkdir command.<\/p>\n<p>This article explains how to use the Linux command line to determine the size of a particular directory. For effective storage management on a Linux system, reliable monitoring of disc space use is essential. Keeping track of individual file sizes is very simple, but measuring the size of an entire directory can be more difficult. Fortunately, Linux has several commands and utilities that let users find out a directory&#8217;s size and how much disc space it takes up.<\/p>\n<h3>Option 1: Show the Directory&#8217;s Size Through the du Command<\/h3>\n<p>Ducommand is an acronym for disc use. Most Linux distributions come with this command by default.<\/p>\n<p>By entering du in the command line, you can see the directory&#8217;s size:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">du<\/pre>\n<p>Your home directory&#8217;s contents should be listed on the screen along with a number to the left. The amount there represents the object&#8217;s kilobyte size.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-282\" src=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/directory-size-du-command.png\" alt=\"display size of directory using du command\" width=\"800\" height=\"406\" srcset=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/directory-size-du-command.png 800w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/directory-size-du-command-300x152.png 300w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/directory-size-du-command-150x76.png 150w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/directory-size-du-command-768x390.png 768w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/directory-size-du-command-100x51.png 100w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/directory-size-du-command-700x355.png 700w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/strong><\/p>\n<p>To make the output easier to read, add the -h option:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">du -h<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-283\" src=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/list-contents-home-directory.png\" alt=\"readable list of contents of home directory \" width=\"800\" height=\"401\" srcset=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/list-contents-home-directory.png 800w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/list-contents-home-directory-300x150.png 300w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/list-contents-home-directory-150x75.png 150w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/list-contents-home-directory-768x385.png 768w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/list-contents-home-directory-100x50.png 100w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/list-contents-home-directory-700x351.png 700w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Each entry will be preceded by a letter and a number. The letter (often K, M, or G) stands for Kilobytes, Megabytes, or Gigabytes, while the number is the amount of space used. For instance:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">400K \u2013 400 kilobytes\r\n7.3M \u2013 7.3 megabytes\r\n2.2G \u2013 2.2 gigabytes<\/pre>\n<p>To determine a directory&#8217;s size distinct from your current working directory. You can provide a guide to inspect with the du command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">du -h \/var<\/pre>\n<p>This shows the volume of the \/var directory&#8217;s contents. You can come across some entries containing mistakes, as in the picture below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-284\" src=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/get-size-specific-directory.png\" alt=\"display size of specific directory \" width=\"800\" height=\"345\" srcset=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/get-size-specific-directory.png 800w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/get-size-specific-directory-300x129.png 300w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/get-size-specific-directory-150x65.png 150w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/get-size-specific-directory-768x331.png 768w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/get-size-specific-directory-100x43.png 100w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/get-size-specific-directory-700x302.png 700w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>This occurs when your user account is denied access to a specific directory. To gain access rights, use the sudo or su command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo du -h \/var<\/pre>\n<p>Use the -c command to view the total disc use of a certain directory:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo du -c \/var<\/pre>\n<p>You can combine options. Enter the following if you want to repeat the previous command in human-readable form:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo du -hc \/var<\/pre>\n<p>Using the max-depth option, you can restrict the scan to a specific level of subfolder. Use &#8211;max-depth=0, for instance, to scan only the top directory&#8217;s size.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo du -hc --max-depth=0 \/var<\/pre>\n<p>Change &#8211;max-depth=1 to only list the root directory and the top-level subdirectories:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo du -hc --max-depth=1 \/var<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-285\" src=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/find-size-top-directory.png\" alt=\"get list of only top directory using command\" width=\"800\" height=\"137\" srcset=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/find-size-top-directory.png 800w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/find-size-top-directory-300x51.png 300w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/find-size-top-directory-150x26.png 150w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/find-size-top-directory-768x132.png 768w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/find-size-top-directory-100x17.png 100w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/find-size-top-directory-700x120.png 700w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Enter the following command to view the help file if you need assistance or want to learn more about the options available with the du command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">man du<\/pre>\n<h3>Option 2: Some Linux Versions may not have the tree command by default.<\/h3>\n<p>Enter the Next to Install it:<\/p>\n<p>The visual representation of your folders is shown by the tree command. It utilizes colors to represent folders and files, and lines to show which subdirectories belong where.<\/p>\n<p><strong>For the Intent of Debian \/ Ubuntu<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo apt-get install tree<\/pre>\n<p><strong>For the Intent of CentOS \/ RedHat<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo yum install tree<\/pre>\n<p>The visual representation of your folders is shown by the tree command. It utilizes colors to represent folders and files, and lines to show which subdirectories belong where. The tree can be combined with choices as well. Enter the following to see the size of the subdirectories in the current directory in human-readable form:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">tree -d -h<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-286\" src=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/display-disk-usage-tree-command.png\" alt=\"using the tree command show disk usage\" width=\"800\" height=\"318\" srcset=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/display-disk-usage-tree-command.png 800w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/display-disk-usage-tree-command-300x119.png 300w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/display-disk-usage-tree-command-150x60.png 150w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/display-disk-usage-tree-command-768x305.png 768w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/display-disk-usage-tree-command-100x40.png 100w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/display-disk-usage-tree-command-700x278.png 700w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Similar to the du command, the tree can focus on a certain directory:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">tree \/var<\/pre>\n<p>Due to the large number of items in the \/var directory, this command takes some time.<\/p>\n<p>You may access the help file for the tree command by typing the following:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">man tree<\/pre>\n<h3>Option 3: Using the ncdu Command, Determine the Size of a Linux Directory<\/h3>\n<p>NCurses Disc Usage stands for the ncdu utility. It is not always installed by default on some Linux versions, just like the tree command. Enter the next step to install it:<\/p>\n<p>Regarding Debian\/Ubuntu:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo apt-get install ncdu<\/pre>\n<p>Regarding CentOS \/ RedHat:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sudo yum install ncdu<\/pre>\n<p>Your disc consumption is displayed interactively by the NCDU tool. Enter the following, for instance:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ncdu<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-287\" src=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/using-ncdu-command-display-disk-usage.png\" alt=\"show disk usage by ncdu command\" width=\"800\" height=\"501\" srcset=\"https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/using-ncdu-command-display-disk-usage.png 800w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/using-ncdu-command-display-disk-usage-300x188.png 300w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/using-ncdu-command-display-disk-usage-150x94.png 150w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/using-ncdu-command-display-disk-usage-768x481.png 768w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/using-ncdu-command-display-disk-usage-100x63.png 100w, https:\/\/www.dedicatedcore.com\/blog\/wp-content\/uploads\/using-ncdu-command-display-disk-usage-700x438.png 700w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>It shows the directory that is now being scanned in the top left corner. The file or directory, the numerical size, and a graph of #- signs to show the relative size are all displayed in a column on the left.<\/p>\n<p>To choose alternative lines, use the up and down arrows. The left arrow will return you, and the right arrow will navigate you to a directory. When using ncdu to target a particular directory, for instance:<\/p>\n<p>It shows the directory that is now being scanned in the top left corner. The file or directory, the numerical size, and a graph of #- signs to show the relative size are all displayed in a column on the left. To choose alternative lines, use the up and down arrows. The left arrow will return you, and the right arrow will navigate you to a directory. When using ncdu to target a particular directory, for instance:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ncdu \/var<\/pre>\n<h4>Final Thought on How to Get the Size of a Directory in Linux<\/h4>\n<p>In this tutorial, we looked at using the du command to determine the overall size of a directory in Linux. As you can see, finding the size of a directory or folder in Linux is not difficult. In Linux operating systems, you have three choices for determining a directory&#8217;s size.<\/p>\n<p>Users who are aware of the size of Linux folders are better equipped to allocate storage space wisely, spot areas for improvement, and guarantee effective disc space usage. It makes it easier to organize things well, clean up when necessary, and take preventative maintenance measures to avoid running out of space or using up unneeded resources. When managing directory sizes, you may need to extract archived files to analyze their contents. Learn how to efficiently <a href=\"https:\/\/www.dedicatedcore.com\/blog\/extract-unzip-tar-gz-file-linux-command\/\" target=\"_blank\" rel=\"noopener\">decompress tar.gz files<\/a> in Linux using the tar command for seamless file handling.<\/p>\n<h3>Frequently Asked Questions (FAQ)<\/h3>\n<p><strong>1. Why would I need to find the Size of a Directory in Linux?<\/strong><\/p>\n<p>Knowing the size of the directory helps you manage disk space, recognize large folders consuming resources, and optimize storage, specifically on servers or systems with limited space.<\/p>\n<p><strong>2. Why does it take so long to calculate the size of a large directory in Linux?<\/strong><\/p>\n<p>This question usually gets asked because of the various ways to calculate sizes by recursively searching through many files and subdirectories, and for a slower disk or one with heavy I\/O activity, it becomes slow. At other times, the very system that defines the performance is at fault due to access-inefficient fragmentation. Using better-optimized tools or limiting the scope of the scan may make these calculations quicker.<\/p>\n<p><strong>3. How can I check the size of a directory in Linux?<\/strong><\/p>\n<p>To check the size of a directory in Linux, the commonly used command is the du command. To get the size, use the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">du -sh \/path\/to\/directory<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Linux is frequently run using the command line. However, Linux&#8217;s command line, also referred to as the terminal, lacks an easy-to-use interface for checking disc&#8230;<\/p>\n","protected":false},"author":1,"featured_media":437,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/posts\/279"}],"collection":[{"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/comments?post=279"}],"version-history":[{"count":8,"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":2791,"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions\/2791"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/media\/437"}],"wp:attachment":[{"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dedicatedcore.com\/blog\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}