Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How can I suspend or hibernate my laptop using command line, without installing additional software?

share|improve this question

9 Answers 9

up vote 93 down vote accepted

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. The new method doesn't require root and notifies all applications listening for power events.

New Method

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.

share|improve this answer
8  
pm-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 Aug 9 '10 at 20:52
    
added sudo to the description –  txwikinger Aug 9 '10 at 23:38
1  
Note that you have to apt-get install powermanagement-interface to run pmi. –  nealmcb Feb 10 '12 at 1:47
1  
On 11.10 only pm-* works, also with powermanagament-interface added –  Omegafil Feb 13 '12 at 9:56
1  
doesn't work with my ubuntu 12.10. after apt-get install powermanagement-interface –  somethis Jun 2 '13 at 9:37

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.

  1. It will lock your screen (upon resume) if you have that option selected in gnome.

  2. It does not require root privilege, so it is easy to add it as a keyboard shortcut, for example.

Note: This is basically the same as qbi's answer, but updated to work for newer versions of Ubuntu.

share|improve this answer
10  
Your answer really should be first. It's non-root no-packages-to-be-installed gnome way of doing it. Like! –  turbo Jun 7 '12 at 16:26
    
That's the right answer! :D –  dadexix86 Jun 23 '12 at 12:04
1  
AFAIK 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). –  Petr Pudlák Dec 6 '12 at 21:24
    
While this is actually the right way to do it (tm), SSH users should take note of : askubuntu.com/questions/21586/… –  airtonix Jul 30 '13 at 0:52
10  
To Hibernate, you can simply replace the last line with org.freedesktop.UPower.Hibernate –  Sheharyar Aug 11 '13 at 8:46

(English)

If you just want your computer to suspend in one hour because you want to go to bed listening to your favorite radio station, just open terminal and type :

sudo bash -c "sleep 1h; pm-suspend"

and your computer will fall asleep in 1 hour, and when you awake, he 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!

(Francais)

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, et 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!

share|improve this answer
    
Perfect, easiest solution! –  wakeup Feb 12 at 2:19
    
That's my use case I'm looking for! AFIK pm-* can be run without superuser permissions –  ruX Jul 28 at 22:49

For Ubuntu 12.04 LTS & Ubuntu 13.04

To get Hibernation

        sudo pm-hibernate

To get Suspend

        sudo pm-suspend
share|improve this answer
    
"sudo pm-suspend" not working on mint 13 mate :( –  rsjethani Nov 23 '12 at 10:16
    
Yeah I think that package was not installed . look for those packages in synaptic. –  AgentCool Nov 23 '12 at 17:34
    
the package is installed, I think 'mate-power-manager' is interfering with it. –  rsjethani Nov 23 '12 at 20:22
    
Perfect, 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. –  Maks Oct 22 at 10:05

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:

# 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.Hibernate

According to this entry in launchpad the above interface was removed. So it would not work anymore in Ubuntu.

share|improve this answer
    
First 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" –  user1034 Aug 9 '10 at 20:58
    
I added a small explanation to the /sys/power/state-thing. Furthermore the dbus method was removed from Ubuntu so it won't work anymore. –  qbi Aug 9 '10 at 21:45
    
$ sudo echo -n mem > /sys/power/state - bash: /sys/power/state: Permission denied –  Hubro Aug 24 at 21:01
    
This 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 to sudo tee like so: echo mem | sudo tee /sys/power/state –  RandomInsano Sep 1 at 4:22

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:

$ gnome-screensaver-command --lock && pmi action hibernate

I imagine this does not depend on the gnome configuration, but I haven't tested that.

share|improve this answer

To shutdown a system (14.04) from the command line (or keyboard shortcut) use:

dbus-send --system --print-reply --dest="org.freedesktop.login1" /org/freedesktop/login1 org.freedesktop.login1.Manager.PowerOff boolean:true

I found this out by playing around with gdbus which can list the interfaces available:

To list the services available on the bus:

dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames

To find the methods:

gdbus introspect --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1 --recurse
share|improve this answer

Personally, I've been experimenting with the pmi method. However, when I tried this, I got an error message: Error org.freedesktop.DBus.Error.Spawn.ChildExited: Launch helper exited with unknown return code 1. However, there is a workaround in the 3rd comment of this bug report, which seems to have worked for me (I'm using Ubuntu 13.03).

share|improve this answer
    
Whilst 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. –  fossfreedom Aug 31 '13 at 7:37

Here's how to put a remote machine in standby over ssh:

ssh -t 192.168.1.4 'sudo nohup &>/dev/null bash -c "(sleep 1; echo -n mem >/sys/power/state) &"'
x@192.168.1.4's password: 
[sudo] password for x: 
Connection to 192.168.1.4 closed.

/sys/power/state works in Ubuntu 13.10. pmi gives Dbus error.

share|improve this answer

protected by AgentCool Aug 11 at 10:35

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.