{"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
Linux users can use the The The or<\/p>\n\n\n\n Any path that starts with a forward slash You can remove the The du command You can sort the output by size by using the following command syntax:<\/p>\n\n\n\n You can use the If you do not specify any file or directory in your command, 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":"\ndu<\/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
du<\/code> command allows users to check by relative path or absolute path using the syntax as shown below.<\/p>\n\n\n\n
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
$ du -hs relative\/path\/to\/directory<\/code><\/pre>\n\n\n\n
\/<\/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
-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
-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
$ du -h \/path\/to\/directory | sort -rh<\/code><\/pre>\n\n\n\n
-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
du<\/code> will return the disk usage of current working directory.<\/p>\n\n\n\n
Conclusion<\/h2>\n\n\n\n