I was recently (and again) quite rudely reminded of a situation wherein your laptop running Ubuntu Desktop doesn’t automatically shut down when you close the lid, meaning you can end up with a low or dead battery! And you can’t find a setting for that. Well, that’s because the Canonical and Ubuntu folk decided not to expose that setting. But there is one! Actually, there are three. You’ll need to change these settings the hard (but fun) way – from the terminal: You’ll need admin privileges (sudo, nano or your favored and capable editor).
Open the /etc/logind.conf file in an editor, find three commented #HandleLidSwitch lines, and either uncomment and change them, or insert new lines, as shown below.
sudo nano /etc/systemd/logind.conf
HandleLidSwitch=poweroff
HandleLidSwitchExternalPower=poweroff
LidSwitchIgnoreInhibited=yes
The first change is effective when the device is running on battery power; the second is for running on external power (charger). The third change tells the system NOT to ignore the lid switch!
You’ll need to reboot for these changes to become effective. (There may be other ways but I usually prefer a fresh start.)
For the record, my most recent rude reminder was in the form of a completely dead battery when an Acer laptop came out of its case. That’s right, 0%. Ouch! Thanks, Canonical.