To find the size of a folder in gigabytes (GB) using the shell, you can use the du
command with the -sh
option. Here’s the command you can use:
du -sh /path/to/folder | awk '{print $1/1024 "GB"}'
Let’s break down the command:
- du is a command used to estimate file and directory sizes.
- -sh is a combination of options:
- -s provides a summary of the specified folder’s total size.
- -h displays the output in human-readable format.
- /path/to/folder should be replaced with the actual path to the folder you want to measure.
The command calculates the folder size and then pipes the output to awk. awk is used to divide the size by 1024 to convert it from kilobytes to gigabytes, and then it appends “GB” to the result for clarity.
After running the command, you should see the total size of the folder in gigabytes.