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.
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
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.
You can use the file /sys/power/state to do this. First find out what states are supported:
user@linux:_> cat /sys/power/state
standby mem disk
root@linux:~> echo -n mem > /sys/power/state # suspend to ram
root@linux:~> echo -n disk > /sys/power/state # suspend to disk
Adam Paetznick's dbus-send answer didn't work as purported for me on lucid; the machine woke up unlocked, even though the gnome-power-manager is set to lock the screen on wake-up.
I want the screen to be locked at wake-up, and found that the following does that:
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)and
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:
and
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
andsudo pm-hibernate
to work on my netbook.The gnome-friendly way is to use dbus.
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 toHibernate
creates a hibernate command: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)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:
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 :
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:
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!
To get Hibernation:
To get Suspend:
You can use the file
/sys/power/state
to do this. First find out what states are supported:or via dbus:
# Suspend dbus-send --session --dest=org.gnome.PowerManager \ --type=method_call --print-reply --reply-timeout=2000 \ /org/gnome/PowerManager org.gnome.PowerManager.Suspend #Hibernate dbus-send --session --dest=org.gnome.PowerManager \ --type=method_call --print-reply --reply-timeout=2000 \ /org/gnome/PowerManager org.gnome.PowerManager.HibernateAccording to this entry in launchpad the above interface was removed. So it would not work anymore in Ubuntu.
since 15.04 systemD is the standard init system so there is a new command to be used:
To suspend a system (14.04) from the command line (or keyboard shortcut) use:
I found this out by playing around with gdbus which can list the interfaces available:
To list the services available on the bus:
To find the methods:
Adam Paetznick's dbus-send answer didn't work as purported for me on lucid; the machine woke up unlocked, even though the gnome-power-manager is set to lock the screen on wake-up. I want the screen to be locked at wake-up, and found that the following does that:
I imagine this does not depend on the gnome configuration, but I haven't tested that.
New interface
…which works in 15.10 Wily, and possibly Utopic and Vivid.
Helpfully this doesn't require sudo, unlike the
pm-suspend
command.Here's how to put a remote machine in standby over ssh:
/sys/power/state works in Ubuntu 13.10. pmi gives Dbus error.