How to Check Directory Size in Linux?
Direct Answer:
To check the size of a directory in Linux, you can use the du
command. This command stands for "disk usage" and is used to estimate the size of a directory. Here are the common ways to use the du
command:
- Method 1: Simple Directory Size Check
- Open a terminal and type
du -sh /path/to/directory
- Replace
/path/to/directory
with the actual path of the directory you want to check. - The
-s
option stands for "summary" which displays the total size of the directory and its contents. - The
-h
option stands for "human-readable" which displays the size in a human-readable format (e.g., KB, MB, GB, TB).
- Open a terminal and type
- Method 2: Directory Size Check with Subdirectories
- Open a terminal and type
du -ah /path/to/directory
- Replace
/path/to/directory
with the actual path of the directory you want to check. - The
-a
option stands for "all" which includes the size of subdirectories in the count. - The
-h
option stands for "human-readable" which displays the size in a human-readable format (e.g., KB, MB, GB, TB).
- Open a terminal and type
Using Other Linux Commands to Check Directory Size
Besides the du
command, there are other ways to check the size of a directory in Linux:
- Disk Usage – Human Readable (DUF)
- Install DUF:
sudo apt-get install duf
(for Ubuntu-based systems) orsudo yum install duf
(for RHEL-based systems) - Open a terminal and type
duf --human-readable /path/to/directory
- Replace
/path/to/directory
with the actual path of the directory you want to check
- Install DUF:
- Tree
- Install Tree:
sudo apt-get install tree
(for Ubuntu-based systems) orsudo yum install tree
(for RHEL-based systems) - Open a terminal and type
tree -d /path/to/directory --du
- Replace
/path/to/directory
with the actual path of the directory you want to check - The
-d
option stands for "directories only" which excludes files from the count - The
--du
option stands for "show disk usage" which displays the size of the directory and its contents
- Install Tree:
Using Graphical Tools
If you prefer a graphical interface, you can use the following tools:
- Baobab
- Install Baobab:
sudo apt-get install baobab
(for Ubuntu-based systems) orsudo yum install baobab
(for RHEL-based systems) - Open Baobab and navigate to the directory you want to check
- Right-click on the directory and select "Properties" or "Get Info"
- The "Properties" or "Get Info" window will display the size of the directory
- Install Baobab:
- File Manager (Nautilus)
- For Ubuntu-based systems: Right-click on the directory you want to check and select "Properties"
- For RHEL-based systems: Right-click on the directory you want to check and select "Get Info"
- The "Properties" or "Get Info" window will display the size of the directory
Tips and Tricks
- Enter the directory path carefully: Make sure to enter the correct path of the directory you want to check, as this can lead to incorrect results.
- Use the correct options: Pay attention to the options you use with the
du
command, such as-s
for a summary and-h
for human-readable format. - Be patient: The
du
command can take some time to scan a large directory, so be patient and do not interrupt the process.
Conclusion
In conclusion, checking the size of a directory in Linux is a straightforward process that can be done using various commands and tools. Whether you prefer a command-line interface or a graphical one, there are options available to suit your needs. By following the methods outlined in this article, you can easily check the size of a directory in Linux and make informed decisions about your file management.
Additional Resources
- Linux daemon: UCF
- DUF: DUF on GitHub
- Tree: Tree on GitHub
- Baobab: Baobab on GitHub
- Nautilus: Nautilus on GitHub