Table of Contents
Computers are quite advanced machines these days. But even they can face the problem of insufficient memory on the hard disk. To understand how to fix this problem, you need to understand what exactly takes up space on your computer. In this article, we will talk and show you how to find out what is using disk space in Linux.
Why do I need to free up disk space?
How to find out what is taking up disk space on Linux:
Method 1:
To find out the size of files and directories, you can use the du (short disk usage) command.
Write du -sh * and the output will look like this:
342 folder
628 folder1
99 file.sh
What do the -sh * keys mean:
-s – displays the size only for the folder passed as an argument, not for each file in that folder.
-h – displays the sizes in a human-readable form (2K, 18M, 4G)
* – selects all objects in the current directory for counting.
To take a closer look at a folder, use the following syntax to navigate deeper into the folder:
du / path_to_directory
For example, du -ah/var / log
-a – displays the size for all files, not just directories.
This method may not seem convenient enough, so we will look at the second option.
Method 2:
Using the ncdu command (NCurse Disk Usage)
You can install ncdu through the terminal with the «sudo apt-get install ncdu» command.
Enter the command and wait for it to calculate the used space.
The results will be displayed as a list with the relative path and size of each object.
The ncdu command has a pseudographic interface, that is why it will be easier and more convenient to use it.
The arrow keys are used to navigate. Use the up and down keys to select an item, and use the left and right keys or the Enter key to enter the selected categories.
Another distinguishing feature of the ncdu command is the hotkeys that are used for control.
Some of them are presented below:
a – switching to the mode of displaying the actual used disk space in bytes
q and b – exit the program to the console
d – delete the selected object
e – show only hidden files
g – switch to the mode of displaying the used place as a percentage
i – display information about a file or folder
k and j – same as up-down keys
n and s – sort by name and size
r – recalculation of used space
Unfortunately, both methods do not have a convenient graphical interface, and therefore it is not so easy to work with them in order to find out what is taking up disk space.
There are many third-party utilities that have a great interface and advanced functionality. With them, you can easily and visually be able to find out what is taking up disk space on your computer.