Skip to main content

To determine the size of a directory using the terminal, you can use the du (disk usage) command. The syntax for this command can vary slightly depending on the operating system you are using, but a common way to use it is as follows:

 

For Linux and macOS

du -sh /path/to/directory
du Disk usage
-s Summarise the total size of the directory and do not include the size of each individual file within the directory
-h Human-readable format, making the size easier to understand (e.g., displaying 1K for one kilobyte, 234M for 234 megabytes, etc.)
/path/to/directory Replace this with the path to the directory you want to check

This command will output the total size of the directory in a human-readable format.

Such as, to find the size of the files directory ~ /var/www/html/project/sites/default/, running the command du -sh files/ in UAT environment

15G    files/

Whereas, in the respective Production environment

23G    files/

 

Windows

To check the size of a directory named Documents in the current user's home directory, you would use:

du -sh ~/Documents

If you are using a Windows system, you would typically use PowerShell or the Command Prompt, and the command would be different. For example, in PowerShell, you can use:

Get-ChildItem -Path 'C:\path\to\directory' -Recurse | Measure-Object -Property Length -Sum

This command will give you the size in bytes. To convert it into a more readable format, you might need to do some additional calculations or formatting.

Related articles

Andrew Fletcher16 Jan 2025
get IP address from terminal OSX
When troubleshooting network issues or configuring devices, knowing your IP address can be essential. Whether you're connected via Wi-Fi, Ethernet, or tethering through a mobile provider, macOS offers powerful built-in tools to quickly identify your IP address. Here's a practical guide tailored to...