Examining your Linux system’s disk space is important to control and ensure the smooth operation of the system. Moreover, you can investigate and manage the remaining storage space on your disk by using commands such as df, du, ls, and ncdu. Overall, these tools will help you maintain an efficient and well-organized system.
In this article, we will explore the top four commands for checking the disk space on Linux.
To check the free space on your disk, you can use the below-listed commands:
Now, let’s check out the usage of the above-listed commands.
The df command in Linux shows you information about how much space is used in all the connected storage areas.
To make the information easier to understand, you can use the -h option with the df command in Linux:
|$ df -h
This option shows the sizes in units like megabytes, and gigabytes, and makes the output more human-readable.
You can use the Linux ls command with the -lh options for listing files in a directory along with their sizes in a human-readable format:
|$ ls -lh /home/linux
When you want to see how much space a specific directory is taking up, use the du command in Linux. It helps you check the storage usage in a particular folder.
For clear results, add -h to the du command in Linux for human-readable sizes. Also, you can use –max-depth to limit the search to the desired levels:
|$ du -h –max-depth=2 /home/linux
As a result, the output shows only the sizes of the subdirectories.
|$ sudo apt-get install ncdu
Now, we will execute the ncdu / command:
|$ sudo ncdu /
This command opens ncdu with special permissions, allowing it to scan and show detailed info about how the disk space is used in the root directory.
Additionally, you can include a specific directory to see detailed information, such as total disk usage, apparent size, and the number of items it contains:
|$ ncdu /home/karim
In this write-up, we have covered content related to Linux commands like df, du, ls, and ncdu for checking and managing disk space. Applying these methods helps you understand and organize your system’s storage effectively.