To get the size of a directory in Linux, you can use the du
command. The du
command stands for "disk usage" and it is used to estimate the space used by a file or directory.
To get the size of a directory and its contents, open a terminal window and enter the following command:
du -sh <directory>
Replace <directory>
with the path to the directory that you want to get the size of. For example, to get the size of the directory /home/user/Documents
, you would enter the following command:
du -sh /home/user/Documents
The output of the command will display the size of the directory in a human-readable format, such as "10M" for 10 megabytes or "1G" for 1 gigabyte, as well as the path to the directory. For example:
10M /home/user/Documents
If you want to get the size of each subdirectory within the directory, you can use the -s
option to display only a summary of the sizes, and the -h
option to display the sizes in a human-readable format. For example:
du -sh /home/user/Documents/*
This will display the size of each subdirectory within /home/user/Documents
.
Comments
Post a Comment