To optimize Ubuntu system using the command line, you can perform actions like cleaning up disk space, removing old package caches, managing startup applications, and adjusting CPU governor settings.
Key commands for optimizing Ubuntu:
Update & Upgrade the System:
Keep system up to date to ensure you have the latest security patches and performance improvements.
sudo apt update && sudo apt upgrade -y
Disk space cleaning:
sudo apt autoremove
sudo apt clean # Clears the local package cache.
sudo apt autoclean # Removes only obsolete packages from the cache.
sudo rm /var/log//.log # Deletes old system logs
sudo find /tmp -type f -delete # Removes temporary files from the /tmp directory
Clean unused files:
sudo journalctl --vacuum-time=3d
Startup application management:
systemd-analyze blame # Shows which services are taking the longest to start on boot
sudo systemctl list-units --type=service --state=running
sudo systemctl disable SERVICE_NAME # Disables a service from automatically starting on boot
CPU performance optimization:
cpupower frequency-info # Displays current CPU frequency settings
sudo cpufreq-set -g performance # Sets CPU governor to "performance" for maximum speed
sudo cpufreq-set -g powersave # Sets CPU governor to "powersave" for maximum battery life
RAM management:
free -h # Shows current RAM usage
top # Displays a list of running processes and their memory usage
sudo kill # Kills a process by its process ID (PID)
sudo sync && sudo sysctl -w vm.drop_caches=3
Optimize Swap Usage:
# Check the current swappiness value:
cat /proc/sys/vm/swappiness
# To reduce unnecessary swapping (recommended: 10-20):
sudo sysctl vm.swappiness=10
echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.conf
Important Considerations:
Always use sudo before commands that require root access to modify system settings.
Backup your system before making significant changes.
Understand the impact of each command before executing it, as some settings may affect system performance depending on your usage.