How can I suspend/hibernate from command line?
Solution 1
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.
Solution 2
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.
Solution 3
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!
Solution 4
To get Hibernation:
sudo pm-hibernate
To get Suspend:
sudo pm-suspend
Solution 5
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
or via dbus:
According to this entry in launchpad the above interface was removed. So it would not work anymore in Ubuntu.
Related videos on Youtube
user1034
Updated on September 17, 2022Comments
-
user1034 over 1 year
How can I suspend or hibernate my laptop using command line, without installing additional software?
-
CJlano almost 8 yearsFor Ubuntu 16.04, see this question: askubuntu.com/questions/777178/suspend-command-in-ubuntu-16-04 and its answer
systemctl suspend
-
-
user1034 almost 14 yearspm-suspend and pm-hibernate works for me and it's easy. Requires sudo but that's OK. (Found pmi idea before but installing a package to use suspend is well bad...)
-
user1034 almost 14 yearsFirst idea gives me: "bash: echo: write error: Invalid argument" Dbus idea gives output: "Error org.freedesktop.DBus.Error.UnknownMethod: Method "Suspend" with signature "" on interface "org.gnome.PowerManager" doesn't exist"
-
qbi almost 14 yearsI added a small explanation to the
/sys/power/state
-thing. Furthermore the dbus method was removed from Ubuntu so it won't work anymore. -
txwikinger almost 14 yearsadded sudo to the description
-
nealmcb over 12 yearsNote that you have to
apt-get install powermanagement-interface
to run pmi. -
Omegafil about 12 yearsOn 11.10 only pm-* works, also with powermanagament-interface added
-
David Guo almost 12 yearsYour answer really should be first. It's non-root no-packages-to-be-installed gnome way of doing it. Like!
-
dadexix86 almost 12 yearsThat's the right answer! :D
-
rsjethani over 11 years"sudo pm-suspend" not working on mint 13 mate :(
-
mx7 over 11 yearsYeah I think that package was not installed . look for those packages in synaptic.
-
rsjethani over 11 yearsthe package is installed, I think 'mate-power-manager' is interfering with it.
-
Petr over 11 yearsAFAIK there is another advantage: It allows other program to detect that suspend/resume happened and act accordingly (for example an IM to resume a network connection to a server).
-
somethis almost 11 yearsdoesn't work with my ubuntu 12.10. after
apt-get install powermanagement-interface
-
airtonix almost 11 yearsWhile this is actually the right way to do it (tm), SSH users should take note of : askubuntu.com/questions/21586/…
-
nilsonneto over 10 yearsWhilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
-
Patryk over 10 yearsUnder 13.10 I get
Error org.freedesktop.UPower.GeneralError: not authorized
-
user2399705 about 10 yearson my 13.10 it does work. however, the screen is not locked upon resume, even though in "Security and Privacy", "Require my password when waking from Suspend" is activated.
-
Gui Ambros almost 10 yearsDidn't work for me (Gnome 3.12, Ubuntu 14.04). Seems the [UPower.Suspend] interface was removed, according to bugs.launchpad.net/ubuntu/+source/gnome-power-manager/+bug/…
-
ruX almost 10 yearsThat's my use case I'm looking for! AFIK pm-* can be run without superuser permissions
-
Hubro over 9 years
$ sudo echo -n mem > /sys/power/state
-bash: /sys/power/state: Permission denied
-
RandomInsano over 9 yearsThis works great. For people having problems with this method when using sudo, the "pipe to file", aka ">" is running in your current shell, so it doesn't get super user privileges while your echo did. You'll need to use
sudo -i
first, or pipe tosudo tee
like so:echo mem | sudo tee /sys/power/state
-
jhrs21 over 9 yearsPerfect, thanks the pm-suspend was exactly what I was after without having to install all the X related junk with the powermanagement-interface package. All that's needed to use pm-* is the the pm-utils package.
-
Stenner93 about 9 yearsThe drawback of this method is that if you are using the GUI, pm-suspend will NOT block your session, which can be insecure.
-
ijk about 9 yearsnew method is now broken see unix.stackexchange.com/questions/153099/…
-
Sathiya Narayanan almost 9 years
sudo pm-hibernate
is amazing for making SATA drives really hotplug! :) -
Khurshid Alam almost 9 yearsSuspend interface was moved to logind; askubuntu.com/questions/652978
-
redchief over 8 years
sudo pm-suspend
works well but while waking up after doing so doesn't ask me for password. what should I do. -
Sk4ry over 8 yearsIt works on ubuntu 15.10, too.
-
Vitaly Zdanevich about 8 yearsworks on 14.04 lts
-
phil294 about 8 yearsnone of the above works, even with sudo rights. not the
pm-hibernate
,pmi action hibernate
, not thedbus
stuff. I am sad. -
ichbinblau about 8 yearsI'm using Xubuntu 15.04. The command
systemctl suspend
does suspend the computer, but it does not cause the screen to be locked, even though I've checked the "Lock screen when system is going for sleep" checkbox in Settings -> Power Manager -> Security. Anyone have any idea why? -
ichbinblau almost 8 yearsI've upgraded to Xubuntu 16.04. The command
systemctl suspend
still suspends the computer. Now, it also causes the screen to be locked, if and only if the "Lock screen when system is going for sleep" checkbox in Settings -> Power Manager -> Security is checked. -
Victor Schröder over 7 yearsMy XPS 13 9350 with Debian/Gnome was with suspend/hibernate issues when closing the lid. After running this command (and the equivalent for hibernation), it went successfully into suspension (and hibernation) and now closing and opening the lid work as expected!
-
Tobia Zambon over 7 yearsI'm on 16.04 and both
systemctl suspend
andpm-suspend
work; the difference being that the latter does not first lock the screen and requiressudo
to run. -
user1851105 about 7 yearsNice. Or
xscreensaver-command --lock
as the case may be. -
Tfb9 almost 7 yearsPlease evaluate if this gnome-friendly method is not superceded by 'the new command of systemd' as indicated in (askubuntu.com/questions/777178/suspend-command-in-ubuntu-16-04)
-
NullVoxPopuli almost 6 yearsThis didn't work for me under Gnome+i3wm in 18.04
-
Eric almost 4 yearssystemctl suspend -i It required the -i flag for me on ubuntu 18.04
-
Nils almost 4 yearsTo suspend after one hour:
sleep 3600 && systemctl suspend
-
Bashar Al-Abdulhadi over 3 yearsWorks on 20.04 too :)
-
Ryan almost 3 years
systemctl suspend
worked for me on Ubuntu 20.04, although it made me type my password twice. -
Steve Baroti almost 3 yearsevidently, this solution needs the
pm-utils
suite:apt-get install -y pm-utils
:-) -
Abdollah over 2 years
systemctl hibernate
doesn't work for me. I have Ubuntu 18.04.5 LTS on Lenovo-Z50-70. -
Bram over 2 yearsDoesn't work on my 21.10 OS. Even when root, and executed locally:
Unit suspend.target is masked.
-
M.K about 2 years
systemctl hibernate
worked for me inUbuntu 18.04.1 LTS
BUT, while hibernating, the screen seemed to freeze, and also the fans when turning it on where insanely loud for at least 10 seconds... I am not sure why. -
Han about 2 yearsBoth of
systemctl suspend
andsystemctl hibernate
work well on my Ubuntu 14.04 LTS -
questionto42standswithUkraine about 2 yearsWhy the
Systemd Method
header when the method issystemctl
instead? They are not the same. Perhaps still good to have that header for search hits, though.