Linux – sizing and cleaning up space

Analyzing free disk space in Linux. We look at the space occupied by files in directories. We clean the disk from unnecessary files.

Partially the commands are repeated in the article Commands for managing files and folders in Linux.

Analyzing the entire file system for free space

With the first command below, we can quickly check the free disk space. It checks all file storages (hard disks, including virtually partitioned ones) in our system.

With it, you can see many system virtual storages that are not visible during normal use.

So, let’s check everything that we have in the system:

Highlighted in the screenshot below / dev / vda2 this is the main storage location for our data on Linux. Sometimes it can be called differently. We see that it is completely filled. So there is almost no free disk space.

Analyzing the main Linux scratch disk

Now let’s see in our usual form, in the main Linux root partition, which directories and how much space they occupy (at the same time we will sort by size):

Next, let’s analyze one of the busiest directories. Let it be a directory var

Sorting the directory var by content size – from smallest to largest (the screen was made without regard to sorting):

As expected, most of the space used is in logs. Now let’s analyze them and find the “heaviest” sections:

du -hs / var / log / * | sort -h

We found the ultimate problem: the directory / var / log / journal takes up too much space from us.

We act similarly to search for other directories, for example, for the directory home

Cleaning up / var / log / journal

Correct the configuration of the journald file:

sudo nano /etc/systemd/journald.conf

We set limits on sizes:

SystemMaxUse = 50M
SystemMaxFileSize = 3M

We reset the previous rotation of the logs and restart the service:

sudo systemctl kill –kill-who = main –signal = SIGUSR2 systemd-journald.service
sudo systemctl restart systemd-journald.service

All this will clear the directory to 50 megabytes and will not grow it in the future.

Cleaning logs

An article on clearing logs.

Similar Posts

Leave a Reply Cancel reply