Unix : Finding the size of a folder in GB

Shell Scripting @ Freshers.in

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:

  1. du is a command used to estimate file and directory sizes.
  2. -sh is a combination of options:
    1. -s provides a summary of the specified folder’s total size.
    2. -h displays the output in human-readable format.
  3. /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.

Author: user

Leave a Reply