Managing storage space on a server running Ubuntu Server is critical to ensuring system stability and efficiency. The more a server is used, the more caches, logs, unused packets and other data accumulate, taking up valuable disk space. If this data is not paid attention to, the lack of storage space can negatively affect the performance of the server and even lead to a complete interruption of its services.
The goal of this article is to show you step-by-step instructions for cleaning up this data, deleting old logs, managing storage space occupied by unused packages and old kernel versions, and cleaning up temporary files. By following the recommended commands and procedures, you can keep your server clean and efficient, allowing it to run smoothly, even under increased workload.
1. Delete cache and unused files:
Clear temporary files: Temporary files are usually located in directories /tmp
and /var/tmp
.
sudo rm -rf /tmp/* sudo rm -rf /var/tmp/*
Clear the APT cache: APT caches files for software packages. You can delete them with the following command:
sudo apt-get clean
Delete user cache: User cache files are usually located in the directory ~/.cache
. You can delete these files with the following command:
rm -rf ~/.cache/*
2. Management and clearing of logs:
Logs record various system operations and can grow in size over time.
Delete system logs: The logs files are located in the directories /var/log/
and older logs can be deleted to save space.
sudo rm -rf /var/log/*.log
If you want to delete only logs that are older than certain days:
sudo find /var/log/ -name "*.log" -type f -mtime +30 -exec rm -f {} \;
This command deletes logs that are older than 30 days.
Cleaning the systemd logs (journal logs): His logs journalctl
they can take up a lot of space. You can delete older files with the following command:
sudo journalctl --vacuum-time=7d
This deletes logs older than 7 days.
3. Remove unused packages and dependencies:
The system may hold packages and dependencies that are no longer used, taking up valuable space.
Remove unused packages: To remove unused packages:
sudo apt-get autoremove
Cleaning installed packages: APT can keep files from previous package installations, which can be deleted with the following command:
sudo apt-get autoclean
4. Check disk usage:
To see which areas of the system are taking up the most disk space, use the command du
:
sudo du -h --max-depth=1 / | sort -hr
This will display disk usage by directory, helping you identify which directories are taking up the most space.
5. Clean Installed Snap Packages:
The snap
can hold old versions of packages, increasing the space occupied. You can delete these old versions with the command:
sudo snap list --all | awk '/disabled/{print $1, $3}' | while read snapname revision? do sudo snap remove "$snapname" --revision="$revision"; done
6. Cleaning the system of unused kernels:
You may have old versions of the Linux kernel that are taking up space. To delete old cores that are no longer in use, use the command:
sudo apt-get autoremove --purge
7. Clear Litespeed Cache
If your web server is of Litespeed architecture you can use the following command to delete its cache, many times it empties a significant part of the available space, so you will find it very useful!
rm -rf /usr/local/lsws/cachedata/*
8. Clearing logs for Litespeed Web Server
Also, the server's log files can take up huge sizes, so delete them all with the following command.
rm -rf /usr/local/lsws/logs/*.log
Conclusion
Effective storage management on an Ubuntu Server is not only a matter of maintenance but also critical to the smooth running of the server. The accumulation of temporary files, logs, and unused packages can end up putting a heavy burden on the system and causing performance problems or delays. By clearing caches, system logs, and removing old versions of the kernel and other unused packages, you ensure that the system remains fast, efficient and ready to meet increased demands.
By regularly following the commands and procedures outlined in this article, you can maximize the life of your server, reduce the chances of outages due to lack of space, and ensure that your Ubuntu Server continues to run smoothly, providing reliable service to users and your applications.
If you don't have the knowledge and experience we can do it very easily, just contact us here: https://istotexniki.gr/contact