ะ˜ะทะพะฑั€ะฐะถะตะฝะธะต ะฟะพัั‚ะฐ

Powerful Console Commands for Quick System Cleanup on Debian


Cleaning a Debian System with Console Commands


Maintaining the cleanliness and efficiency of a Debian system is an important task for every user. Over time, unnecessary files, outdated packages, and caches accumulate in the system, which can lead to decreased performance and increased disk space usage. This article discusses the main console commands and methods for cleaning a Debian system, helping you free up space and optimize system operation.


Updating the system before cleaning


Before starting the cleanup, it is recommended to update the package list and install the latest software versions. To do this, execute the following commands:


sudo apt update
sudo apt upgrade -y

This ensures that you are working with the most current and stable versions of installed packages.


Cleaning APT cache


APT stores downloaded packages in a cache, which can take up significant space over time. To clear this cache, use the command:


sudo apt clean

This will delete all package files from the cache. There is also the sudo apt autoclean command, which removes outdated packages that are no longer available for installation or update.


Removing unused packages


After uninstalling programs and updates, unnecessary dependencies and packages may remain that are no longer needed by the system. To remove them, use the command:


sudo apt autoremove -y

This will automatically eliminate all redundant dependencies and free up disk space.


Cleaning logs and temporary files


System logs and temporary files can also occupy a significant amount of space. To clear logs, use the command:


sudo journalctl --vacuum-time=7d

This will delete all logs older than 7 days. You can also remove temporary files stored in the /tmp and /var/tmp directories:


sudo rm -rf /tmp/* /var/tmp/*

Be careful when using the rm -rf command; ensure you are deleting only unnecessary files.


Removing old kernels


If multiple kernels are installed on the system, old versions can take up a lot of space. To remove them, use the command:


dpkg -l | grep linux-image

Afterward, you can manually delete old kernels or use the apt utility. For example:


sudo apt remove --purge linux-image-

It is also convenient to use the sudo apt autoremove --purge command, which will automatically remove outdated kernels and related packages.


Using special utilities for cleaning


For more convenient system cleanup, utilities such as deborphan and localepurge can be used.


deborphan allows you to find and remove orphaned libraries and packages that are no longer needed by the system. To install and use it, run:


sudo apt install deborphan
deborphan
sudo apt remove --purge $(deborphan)

This helps eliminate unnecessary libraries and packages.


localepurge deletes localization and language files that are not used on your system. To install and configure it, run:


sudo apt install localepurge
sudo localepurge

You will be able to select the languages you want to keep, and the remaining files will be deleted automatically.


Checking disk usage


To evaluate the effectiveness of cleanup processes and identify the largest files, use commands such as:


du -sh /*

or


ncdu

The first command shows the total size of directories in the root filesystem, while the second is an interactive disk space analysis tool that helps quickly locate large files and directories.


Recommendations for automatic cleanup


To perform regular automatic system cleaning, you can schedule tasks in cron. For example, add the following commands to crontab for daily cache and outdated package cleanup:


0 3 * * * /usr/bin/apt autoclean -y
30 3 * * * /usr/bin/apt autoremove -y

This will help keep the system clean with minimal effort.


Conclusion


Cleaning a Debian system using console commands is a vital part of its maintenance and optimization. Regular execution of the described procedures allows you to free a significant amount of disk space, improve performance, and ensure system stability. It is important to remember to back up important data before mass deletions and to carefully monitor commands, especially when using commands like rm -rf.


Using system utilities and commands for cleaning will help you keep your system organized and prevent issues related to disk space shortages. Regular checks and proactive cleanup are key to long-term and stable operation.


Author: Mikhail Shcherbakov
Published:
Last updated:
Views: 13