First Size /usr: Understanding Disk Usage with du Command
The disk usage command, du, is a powerful tool in Unix-based operating systems, such as Linux, that allows users to view the amount of disk space used by directories and files. In this article, we will focus on using the du command to examine the disk usage of the /usr directory in Linux.
Understanding the /usr Directory
The /usr directory is a critical part of any Linux system, containing the majority of user-related programs, libraries, and documentation. This directory is usually mounted on a separate partition or disk, allowing for better performance and easier maintenance. Understanding the disk usage of the /usr directory is essential for system administrators to ensure optimal performance and allocate resources efficiently.
Using the du Command to Examine Disk Usage
The du command is used to estimate file and directory space usage. By default, it displays the disk usage in a human-readable format (e.g., 1K, 234M, 5G). To examine the disk usage of the /usr directory, open a terminal and type the following command:
$ sudo du -sh /usr
This command will display the total disk usage of the /usr directory in a human-readable format (e.g., 6.2G). The -s flag tells du to include the total size of all files and directories within the specified directory, while the -h flag makes the output more readable by providing sizes in KB, MB, GB, etc.
Selecting Directories within /usr
To examine the disk usage of specific directories within /usr, you can use the wildcard character (*) or specify the directory name directly. For example, to view the disk usage of all directories within /usr that start with the letter 's', use the following command:
$ sudo du -sh /usr/s*
To view the disk usage of a specific directory, such as /usr/share, simply type the directory name after the /usr path:
$ sudo du -sh /usr/share
Excluding Directories from the Output
If you want to exclude specific directories from the output, you can use the --exclude flag followed by the directory name. For example, to view the disk usage of all directories within /usr except for /usr/share, use the following command:
$ sudo du -sh --exclude=share /usr
Viewing Disk Usage for All Subdirectories
To view the disk usage of all subdirectories within /usr, you can use the recursive option (-r or -R) with the du command. This will display the disk usage for each subdirectory, including the total size of all files and directories within them. For example:
$ sudo du -sh -r /usr
- The
ducommand is a powerful tool for examining disk usage in Linux. - The
/usrdirectory is a critical part of any Linux system, containing user-related programs, libraries, and documentation. - By using the
ducommand with various flags and options, you can examine the disk usage of the/usrdirectory, select specific directories, exclude directories from the output, and view disk usage for all subdirectories.
References
- Man page for the
ducommand: https://man7.org/linux/man-pages/man1/du.1.html - Linux Filesystem Hierarchy: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s02.html