The du
command in Linux can be used to display the size of files and directories in a human-readable format, such as GB, MB, or TB. To do this, use the -h
or --human-readable
option, as follows:
du -h /path/to/directory
This will display the size of the directory and its contents in a human-readable format, with sizes rounded to the nearest KB, MB, GB, or TB as appropriate. For example:
$ du -h /var/log
12K /var/log/btmp
4.0K /var/log/lastlog
4.0K /var/log/wtmp
80K /var/log
You can also specify the unit to use with the --block-size
option:
du -h --block-size=1G /path/to/directory
This will display the sizes in units of 1 GB.
Note that the du
command can take some time to run, especially when run on a large directory tree, so be patient while it completes its calculations.