Created
May 24, 2025 19:10
-
-
Save ArtMin96/0188df61657bf4f548184cb1bbfe4b54 to your computer and use it in GitHub Desktop.
Optimize power for Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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