Getting the Size of a Directory in Linux
To get the size of a directory in Linux, you can use the du command. The du command stands for “disk usage” and is used to estimate file and directory space usage. Here’s how you can use the du command to get the size of a directory:
1. Open a terminal or shell on your Linux system.
2. Navigate to the parent directory of the directory you want to measure the size of. You can use the cd command to change directories. For example, if the directory you want to measure is located at /home/user/documents, you can navigate to the parent directory /home/user.
3. Once you’re in the parent directory, run the following command:
du -sh <directory_name>
Replace <directory_name>
with the name of the directory you want to measure. For example, if the directory you want to measure is called “documents”, the command would be:
du -sh documents
The -s
option tells du
to display only the total size of the directory, and the -h
option is used to display the size in a human-readable format (e.g., “10K”, “5M”, “2G”).
4. Press Enter to execute the command.
5. The output will display the total size of the directory you specified.
Note that the du command may take some time to calculate the size of large directories or directories with a large number of files.
Note that the du
command may take some time to calculate the size of large directories or directories with a large number of files.