How to Determine a Folder’s Size In Ubuntu and Linux
By: Bobby
Published on: Jul 13, 2023
< 1 min read.
On a Unix-like operating system such as Ubuntu, you can use the du
command, which stands for “disk usage,” to find out how much disk space a directory and its contents are taking up.
The following command will give you the total disk usage of a directory and its subdirectories in a human-readable format (i.e., bytes, kilobytes, megabytes, gigabytes):
du -sh /path/to/directory
Here’s what the options mean:
-s
: Summarize and only provide a total for the directory specified.-h
: Display the size in a “human-readable” format, showing sizes in KB (kilobytes), MB (megabytes), or GB (gigabytes) as appropriate.
Make sure to replace /path/to/directory
with the path to the directory you’re interested in. The command will then output the total size of that directory and its contents.
For example, if you want to know the disk usage of the /var
directory, you would use:
du -sh /var