Skip to content

Instantly share code, notes, and snippets.

@ArtMin96
Created May 24, 2025 19:10
Show Gist options
  • Save ArtMin96/0188df61657bf4f548184cb1bbfe4b54 to your computer and use it in GitHub Desktop.
Save ArtMin96/0188df61657bf4f548184cb1bbfe4b54 to your computer and use it in GitHub Desktop.
Optimize power for Ubuntu
#!/bin/bash
# Install necessary packages
sudo apt update
sudo apt install -y cpufrequtils tlp
# Set CPU governor to powersave
echo "Setting CPU governor to powersave..."
for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
echo powersave | sudo tee $cpu/cpufreq/scaling_governor > /dev/null
done
# Enable and start TLP
sudo systemctl enable tlp
sudo systemctl start tlp
# Add persistent CPU governor setting
echo "GOVERNOR=\"powersave\"" | sudo tee /etc/default/cpufrequtils > /dev/null
sudo systemctl enable cpufrequtils
# Optional: GNOME Shell restart suggestion if it's over 30% CPU
GNOME_PID=$(pgrep -f "gnome-shell")
if [ -n "$GNOME_PID" ]; then
CPU_USAGE=$(ps -p $GNOME_PID -o %cpu= | awk '{print int($1)}')
if [ "$CPU_USAGE" -gt 30 ]; then
echo "GNOME Shell is using $CPU_USAGE% CPU. Consider restarting it."
fi
fi
echo "✅ Power optimization applied. Reboot recommended."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment