How to Use the du Command to Show Disk Usage One Level Only


Managing the available disk space is a common task for computers. While you may be used to getting the info visually on Windows, you can use the du command on Linux.

The du command is a Unix command that is used to display the disk usage of a file or directory. By default, the du command will take the specified directory and will recursively go through all the directories and report the disk usage in the terminal. For this article, we will be demoing the commands in Ubuntu 22.04.

Let’s take a look:

$du Downloads

Here you can see that first column shows the size of the directories and then in the second column the respective directory is listed.

How to check the disk usage one level only

Now, if you want to check the disk usage of the specified directory and its immediate subdirectories, you can use the “-d” option. For example, to display the disk usage of the “/Download” directory and its immediate subdirectories, you would use the following command:

$du -d1 Downloads

The -d1 option tells the du command to only display the disk usage of directories that are one level below the specified directory. In this example, the du command would only display the disk usage of the specified and immediate directory.

You can also use the -h option to display the disk usage in a human-readable format. For example, the following command would display the disk usage of the /home directory and its immediate subdirectories in human-readable format:

$du -hd1 Downloads

The -h option tells the du command to display the disk usage in human-readable format, which means that the output will be displayed in units of kilobytes, megabytes, gigabytes, and terabytes.

Conclusion

The du command is a powerful tool that can be used to quickly and easily determine the disk usage of a file or directory. You can use this command in the other distributions just the same, you will only need to use the respective file path syntax for your distribution. By using the -d and -h options, you can easily display the disk usage of a file or directory and its immediate subdirectories in human-readable format.

Print Friendly, PDF & Email
Categories