{"id":12734,"date":"2022-10-14T12:46:58","date_gmt":"2022-10-14T16:46:58","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=12734"},"modified":"2022-10-15T06:11:31","modified_gmt":"2022-10-15T10:11:31","slug":"get-the-directory-size-from-the-command-line-in-ubuntu","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/","title":{"rendered":"How to Get the Directory Size from the Command Line in Ubuntu"},"content":{"rendered":"\n

There are no shortage of reasons to get the directory size in any Linux or any Operating system. This guide will show you how to do it with commands that work in Ubuntu or Debian based systems.<\/p>\n\n\n\n

Using the du Command to get the Directory Size<\/h2>\n\n\n\n

Linux users can use the du<\/code> command which is short for “disk usage” to get the directory size from the command line in Ubuntu. With this command you can get disk usage of the files and folders recursively.<\/p>\n\n\n\n

The du<\/code> command allows users to check by relative path or absolute path using the syntax as shown below.<\/p>\n\n\n\n

The du<\/code> command will return an error “du: cannot read directory” if the user has no permissions to on the directory or files. To fix that you should run the commands with sudo<\/code> privileges.<\/p>\n\n\n\n

$ du -hs \/absolute\/path\/to\/directory<\/code><\/pre>\n\n\n\n

or<\/p>\n\n\n\n

$ du -hs relative\/path\/to\/directory<\/code><\/pre>\n\n\n\n

Any path that starts with a forward slash \/<\/code> is an absolute path as show in the first example.<\/p>\n\n\n\n

The du Command Options Explained<\/h2>\n\n\n\n
  • -h<\/code> : Human readable. du will print sizes in human readable format (e.g., 1K, 100M, 4G).<\/li>
  • -s<\/code> : Summarize. du will only display the total size of the specified directories.<\/li><\/ul>\n\n\n\n

    You can remove the -s<\/code> option to display the size of the specified directory as well as the size of the subdirectories inside of that directory separately.<\/p>\n\n\n\n

    The du command -a<\/code> option allows users to get the disk space used by each file as well as subdirectories within the specified directory. The syntax is as follows:<\/p>\n\n\n\n

    $ du -ha \/path\/to\/directory<\/code><\/pre>\n\n\n\n

    You can sort the output by size by using the following command syntax:<\/p>\n\n\n\n

    $ du -h \/path\/to\/directory | sort -rh<\/code><\/pre>\n\n\n\n

    You can use the -r<\/code> option to sort in reverse order from largest to smallest. Leaving out the -r<\/code> option will sort from smallest to largest file.<\/p>\n\n\n\n

    If you do not specify any file or directory in your command, du<\/code> will return the disk usage of current working directory.<\/p>\n\n\n\n

    Conclusion<\/h2>\n\n\n\n

    In this short guide you have seen how to get directory size in Ubuntu Linux systems with options on summarizing, showing human readable forms, and sorting as well as getting individual file sizes.<\/p>\n","protected":false},"excerpt":{"rendered":"

    There are no shortage of reasons to get the directory size in any Linux or any Operating system. This guide will show you how to do it with commands that…<\/p>\n","protected":false},"author":1,"featured_media":12735,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16,18],"tags":[121,183,354,433,449,591,598],"yoast_head":"\nHow to Get the Directory Size from the Command Line in Ubuntu<\/title>\n<meta name=\"description\" content=\"This is how to get the directory size from the command line with examples in Ubuntu Linux systems with available option\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get the Directory Size from the Command Line in Ubuntu\" \/>\n<meta property=\"og:description\" content=\"This is how to get the directory size from the command line with examples in Ubuntu Linux systems with available option\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-14T16:46:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-15T10:11:31+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"How to Get the Directory Size from the Command Line in Ubuntu\",\"datePublished\":\"2022-10-14T16:46:58+00:00\",\"dateModified\":\"2022-10-15T10:11:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/\"},\"wordCount\":343,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg\",\"keywords\":[\"CentOS\",\"Debian\",\"Linux\",\"Optimization\",\"Performance\",\"Tools\",\"Ubuntu\"],\"articleSection\":[\"Articles\",\"Guides\",\"How To\",\"Technology\",\"Tools\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/\",\"url\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/\",\"name\":\"How to Get the Directory Size from the Command Line in Ubuntu\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg\",\"datePublished\":\"2022-10-14T16:46:58+00:00\",\"dateModified\":\"2022-10-15T10:11:31+00:00\",\"description\":\"This is how to get the directory size from the command line with examples in Ubuntu Linux systems with available option\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg\",\"width\":1280,\"height\":680,\"caption\":\"Directory Size from the Command Line\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get the Directory Size from the Command Line in Ubuntu\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/twitter.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Get the Directory Size from the Command Line in Ubuntu","description":"This is how to get the directory size from the command line with examples in Ubuntu Linux systems with available option","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/","og_locale":"en_US","og_type":"article","og_title":"How to Get the Directory Size from the Command Line in Ubuntu","og_description":"This is how to get the directory size from the command line with examples in Ubuntu Linux systems with available option","og_url":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2022-10-14T16:46:58+00:00","article_modified_time":"2022-10-15T10:11:31+00:00","og_image":[{"width":1280,"height":680,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"How to Get the Directory Size from the Command Line in Ubuntu","datePublished":"2022-10-14T16:46:58+00:00","dateModified":"2022-10-15T10:11:31+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/"},"wordCount":343,"commentCount":0,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg","keywords":["CentOS","Debian","Linux","Optimization","Performance","Tools","Ubuntu"],"articleSection":["Articles","Guides","How To","Technology","Tools"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/","url":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/","name":"How to Get the Directory Size from the Command Line in Ubuntu","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg","datePublished":"2022-10-14T16:46:58+00:00","dateModified":"2022-10-15T10:11:31+00:00","description":"This is how to get the directory size from the command line with examples in Ubuntu Linux systems with available option","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2022\/10\/directory-size.jpg","width":1280,"height":680,"caption":"Directory Size from the Command Line"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/get-the-directory-size-from-the-command-line-in-ubuntu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"How to Get the Directory Size from the Command Line in Ubuntu"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/twitter.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/12734"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=12734"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/12734\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/12735"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=12734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=12734"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=12734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}