How can I suspend/hibernate from command line?
Traditionally ubuntu supported a fairly blunt method of suspend and hibernate. Neither would integrate well with other apps and sometimes not even work on some machines. This new method doesn't require root and notifies all applications listening for power events.
Systemd Method
Starting with Ubuntu 16.04, systemctl
call must be used (See Suspend command in Ubuntu 16.04)
systemctl suspend
and
systemctl hibernate
New Method (obsolete)
Obsolete circa Ubuntu 16.04; use systemctl
instead, as above.
See the answer here on this page from Adam Paetznick regarding the use of dbus. Ideally you would create a ~/bin/suspend
shortcut/script that makes the use of this action easy.
For use over ssh, you should modify policykit rules as outlined by Peter V. Mørch
Old Method
According to the Ubuntu Forum you can use the following commands:
pmi action suspend
and
pmi action hibernate
This requires that you install the powermanagement-interface package (not tested).
sudo apt-get install powermanagement-interface
I have also found the commands sudo pm-suspend
and sudo pm-hibernate
to work on my netbook.
The gnome-friendly way is to use dbus.
dbus-send --system --print-reply \
--dest="org.freedesktop.UPower" \
/org/freedesktop/UPower \
org.freedesktop.UPower.Suspend
There are two advantages to this command over pm-suspend
.
It will lock your screen (upon resume) if you have that option selected in gnome.
It does not require root privilege, so it is easy to add it as a keyboard shortcut, for example.
As mentioned in the comments exchanging the Suspend
in the last line to Hibernate
creates a hibernate command:
dbus-send --system --print-reply \
--dest="org.freedesktop.UPower" \
/org/freedesktop/UPower \
org.freedesktop.UPower.Hibernate
If the hibernation throws Error org.freedesktop.UPower.GeneralError: not authorized
your user might not be allowed to hibernate. Edit or create /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
so it contains the following section: (source)
[Re-enable hibernate by default]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
This was tested on UbuntuGnome 14.04.
Note: This is basically the same as qbi's answer, but updated to work for newer versions of Ubuntu as well as including hibernate.
English
If you want your computer to suspend in one hour because you want to go to bed listening to your favorite radio station, open terminal and type:
sudo bash -c "sleep 1h; pm-suspend"
and your computer will fall asleep in 1 hour. When you awake, it will have kept your open images and all your stuff.
You can replace 1h
by what you want: h
for hours, m
for minutes, s
for seconds, d
for days.
Good night!
Français
Si vous voulez juste que votre ordinateur se mette en veille dans une heure parce que vous voulez vous endormir en ecoutant votre radio préférée, ouvrez Terminal et tapez :
sudo bash -c "sleep 1h; pm-suspend"
et votre ordinateur s'endormira dans une heure. Quand vous vous réveillerez, il aura conservé en mémoire vos applications ouvertes.
Vous pouvez remplacer 1h
par ce que vous voulez: h
pour les heures, m
pour les minutes, s
pour les secondes, d
pour les jours.
Bonne nuit!
Español
Si quieres suspender tu computadora en una hora porque quieres ir a dormir escuchando tu estación de radio favorita, tan solo abre el terminal y escribe:
sudo bash -c "sleep 1h; pm-suspend"
y tu computadora se quedará dormida en 1 hora. Cuando despiertes, allí habrán quedado abiertas tus imágenes y todas tus cosas.
Puedes reemplazar 1h
por lo que desees: h
para horas, m
para minutos, s
para segundos, d
para días.
¡Buenas noches!