Determining the size of a directory in Unix is a fundamental task for managing and organizing filesystems. It allows users to assess disk space usage, identify large directories, and optimize storage allocation. To ascertain the size of a directory, Unix provides the ‘du’ command, an abbreviation for “disk usage.”
The ‘du’ command offers various options to tailor the output and cater to specific needs. By default, ‘du’ displays the size of each directory and its subdirectories, making it easy to identify space-consuming directories. Additionally, options like ‘-s’ provide a summary of the total size of all directories, excluding subdirectories, while ‘-h’ humanizes the output, displaying sizes in user-friendly formats such as KB, MB, or GB.