Master Class: Rapid System Cleanup on Ubuntu Using Command Line Tools
Cleaning Ubuntu System Using Console Commands
Maintaining the cleanliness and optimization of the Ubuntu system is an important task to ensure its stable operation and performance. Using console commands is an effective and quick way to clean the system from unnecessary files, free up disk space, and resolve potential issues related to clutter accumulation. In this article, we will review the main commands and methods for cleaning the Ubuntu system.
Updating the system before starting cleaning
Before performing any cleaning, it is recommended to update the list of available packages and install the latest software versions. This will ensure stable operation and eliminate possible errors. The commands used are:
sudo apt update
sudo apt upgrade
Removing unnecessary packages and dependencies
Over time, outdated or unnecessary packages may accumulate in the system that are no longer used. To remove them, use the command:
sudo apt autoremove
It deletes all packages that were installed automatically and are no longer needed by the system. It is also useful to clear the package cache to free up space:
sudo apt clean
This command deletes all downloaded package files from the /var/cache/apt/archives directory. If you need to delete only outdated packages, you can use:
sudo apt autoclean
Cleaning old kernel versions
Ubuntu updates preserve previous kernel versions, which can take up significant space. To remove old kernels, use the command:
sudo apt autoremove --purge
or utilize utilities byobu or ubuntu-cleaner, which automatically remove unnecessary kernels and files. However, be careful not to delete the active system kernel.
Cleaning logs and temporary files
System event logs can take up a lot of space over time. To clean them, use the command:
sudo journalctl --vacuum-time=7d
This command deletes logs older than 7 days. You can also completely clear the system journal:
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s
To delete temporary files and browser caches, you can use commands:
rm -rf ~/.cache/*
or utilize the BleachBit utility for more convenient cleaning, although it requires installation from repositories.
Using specialized cleaning utilities
In Ubuntu, there are utilities that automate the system cleaning process. One such utility is Stacer. It provides a graphical interface for cleaning cache, logs, unnecessary packages, and other temporary files. To install Stacer, run the command:
sudo apt install stacer
After installation, launch the utility and select the necessary sections for cleaning. There are also commands like apt autoremove, already mentioned, and deborphan for finding and removing unnecessary libraries.
Checking disk status and freeing up space
To assess disk usage, use the command:
df -h
This displays the total, used, and free space on all mounted filesystems. To find large files and folders, use commands like:
du -sh /*
or
sudo ncdu /
Note that ncdu is a convenient interactive tool for analyzing disk usage, which requires prior installation:
sudo apt install ncdu
Summary
Cleaning the Ubuntu system using console commands is an important part of maintenance that helps keep the system up-to-date, improve its performance, and free disk space. Regularly performing these procedures minimizes the risk of errors and ensures stable system operation.
Remember that before performing critical operations, it is advisable to back up data, especially if you are unsure about your actions. Using command-line utilities is a powerful tool that requires caution and attentiveness. With the correct approach, system cleaning becomes a quick and safe process.