Disk Yönetimi

In Linux, How to Find the Size of Directory and Subdirectories?

In Linux, How to Find the Size of Directory and Subdirectories?

Before installing any new program on your computer system, the first thing that every user needs to ensure is that the system has a sufficient amount of storage space to hold that program and run it without any performance issues. Similarly, whenever you intend to copy or download files in any of the directories of your computer system, you need to check if that directory has an adequate amount of storage space available or not.

There are multiple ways in which you can check the sizes of the directories and subdirectories within any operating system that is both GUI based and CLI based. However, since the Linux operating system mostly operates with CLI, therefore, its users are generally interested in looking for terminal-based methods of performing any task. Therefore, in today's article, we will be talking about the methods of finding the sizes of directory and subdirectories in Linux Mint 20.

Methods of Finding the Size of Directory and Subdirectories in Linux Mint 20:

For finding the sizes of directory and subdirectories in Linux Mint 20, you can use any of the three methods described below:

Method # 1: Using the “ncdu” Command:

For using the “ncdu” command to find the sizes of directory and subdirectories in Linux Mint 20, you will be required to perform the following steps:

First, we have to launch the terminal in Linux through which we will execute the “ncdu” command as shown in the image below:


Since the “ncdu” command is not installed by default on the Linux systems, therefore, we will first install it by running the following command in the terminal:

$ sudo apt install ncdu


Before running this command, you must ensure that your Internet is working correctly, otherwise, this command will fail to execute. This command will take a few minutes to install the “ncdu” command and all the required dependencies successfully, after which your terminal will display the output shown in the image below:


Now when the “ncdu” command has been installed on our system, we can easily use it to find the sizes of directory and subdirectories by running it in the following manner:

$ ncdu

Here, we only wanted to find the sizes of the Home directory and its subdirectories that is why we did not have to mention any path. However, if you wish to find the size of any directory other than the Home directory, then its path must be mentioned after the “ncdu” command.


The sizes of the Home directory and its subdirectories are shown in the image below:

Method # 2: Using the “du” Command:

For using the “du” command to find the sizes of directory and subdirectories in Linux Mint 20, you will be required to perform the following steps:

Since the “du” command is already installed on the Linux systems, therefore, we do not need to install anything rather we can use this command straightaway in the manner shown below:

$ du -h

Again, if you wish to find the size of a directory other than the Home directory, then you must mention its path after the “du -h” command. Here, the “-h” flag is used to print the output in a human-readable format.


The sizes of the directories within the Home directory are shown in the following image:

Method # 3: Using the “tree” Command:

For using the “tree” command to find the sizes of directory and subdirectories in Linux Mint 20, you will be required to perform the following steps:

The “tree” command is also not installed in the Linux systems by default but it can easily be installed by running the command shown below:

$ sudo apt install tree


Before running this command, you must ensure that your Internet is working correctly, otherwise, this command will fail to execute. In our case, we already have installed the “tree” command on our system for some other purpose that is why our terminal displayed the following output after running this command:


Now we can run the “tree” command to find the sizes of the directory and subdirectories in the manner shown below:

$ tree -d -h

Again, the “-h” flag is used with the “tree -d” command to display the output in a human-readable format. Moreover, if you wish to find the size of any directory other than the Home directory, then you must mention its path right after the “tree -d -h” command.


The sizes of all the directories within the Home directory are shown in the following image:

Conclusion:

By using any of the three methods discussed in this article, one can easily find out the sizes of the directory and the subdirectories within it. Also, we have just demonstrated to you the examples in which we wanted to find out the sizes of the Home directory and the subdirectories within it. However, you can also find the sizes of any other directory and its subdirectories if you wish to, by using very simple methods. All you have to do is to provide the correct paths of those directories after the commands that are discussed above and you will be able to find the sizes of any directories of your Linux Mint 20 system.

Out of all the three methods that are discussed in this article, the first method is useful if you want to have a detailed report about the sizes of a directory and its subdirectories along with the total size. The second method is useful if you wish to have the sizes of even the subdirectories within the subdirectories whereas the third method is useful if you only intend to get the sizes of the first level subdirectories within a directory.

SuperTuxKart for Linux
SuperTuxKart is a great title designed to bring you the Mario Kart experience free of charge on your Linux system. It is pretty challenging and fun to...
Battle for Wesnoth Tutorial
The Battle for Wesnoth is one of the most popular open source strategy games that you can play at this time. Not only has this game been in developmen...
0 A.D. Tutorial
Out of the many strategy games out there, 0 A.D. manages to stand out as a comprehensive title and a very deep, tactical game despite being open sourc...