29

Is there a way to turn off the display (enter power saving mode) using a command?

For example, when the computer is inactive for a specific interval, the screen turns off to conserve energy. Is there a way to manually turn off the screen, yet keep the computer running normally?

This is a notebook, so there's no 'power-off' button on the monitor itself.

Nathan Osman
  • 31,915
  • 40
  • 179
  • 259

6 Answers6

42

I think you are looking for

xset dpms force off

However, you need to make sure that your acpi is enabled. You can check this with

cat /proc/acpi/info

Another option could be

setterm -powersave powerdown
txwikinger
  • 27,944
  • 10
  • 78
  • 101
  • 2
    The first command didn't require sudo for me. – Isaiah Oct 14 '10 at 21:22
  • Me neither. _` ` ` `_ – Nathan Osman Oct 14 '10 at 21:38
  • 5
    Sometimes the Enter keypress as you execute the command can be enough to immediately wake the computer back up again. I usually go with `sleep 0.2s && xset dpms force off` just to be safe. Also, this makes for a nice replacement for locking your screen: `gnome-screensaver-command --lock && sleep 2s && xset dpms force off` – ændrük Oct 14 '10 at 22:01
  • 1
    ok.. took the sudo advisory out :D – txwikinger Oct 14 '10 at 23:27
  • I just did the same thing in kubuntu using info from this answer: xdg-screensaver activate && sleep 2s && xset dpms force off – Joe Feb 18 '13 at 07:26
  • the first command works, but after some seconds the display turns on again! – Tropilio Feb 03 '20 at 16:13
7

I'm running Ubuntu Server without X on a 2007 MacBook Pro. The display is sleeping by itself but won't reactivate when a key is pressed on the keyboard. At this point my fix is to use vbetool. Install using apt-get:

sudo apt-get install vbetool

Then use to turn display on via SSH from a different machine:

sudo vbetool dpms on

Or off:

sudo vbetool dpms off
David Clarke
  • 171
  • 3
  • 5
  • 3
    vbetool is what I search for exactly! It turn the monitor off completely via BIOS VESA drivers/tools. Just like turning off by using hard key of the monitor! – efkan Jan 20 '17 at 12:07
  • doesn'^t work (macbook air old) mmap /dev/zero: Operation not permitted Failed to initialise LRMI (Linux Real-Mode Interface). – france1 Aug 28 '21 at 12:35
3

I have made a unity launcher to turn off the LCD

sudo apt-get install --no-install-recommends gnome-panel

gnome-desktop-item-edit ~/Desktop/ --create-new

It will open a small windows. Enter the following:

Name: turnofflcd

Command: gnome-screensaver-command --lock && sleep 2s && xset dpms force off

You can also choose an icon by clicking the icon on the left .

For more on making launcher see http://www.ubuntugeek.com/how-to-create-desktop-launchers-in-ubuntu-11-10oneiric.html.

Ian Mackinnon
  • 1,274
  • 2
  • 21
  • 46
gunjan parashar
  • 1,347
  • 6
  • 26
  • 44
1
(sleep 10; xset dpms force suspend) & xdg-screensaver lock

This starts the screen saver in locked mode and then puts your display in standby. Ubuntu Mate 15.10

wjandrea
  • 14,109
  • 4
  • 48
  • 98
blazedego
  • 171
  • 1
  • 3
1

xset dpms force off worked only for 5 seconds.

I searched the internet and found the following script, and after a small change it worked perfectly.

#!/usr/bin/python
import time
import subprocess
from Xlib import X
from Xlib.display import Display
display = Display(':0')
root = display.screen().root
root.grab_pointer(True,
       X.ButtonPressMask | X.ButtonReleaseMask | X.PointerMotionMask,
       X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
root.grab_keyboard(True,
       X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)
subprocess.call('xset dpms force off'.split())
#original
#p = subprocess.Popen('gnome-screensaver-command -a'.split())
#changed
p = subprocess.Popen('xset dpms force off'.split())
time.sleep(1)
while True:
   print display.next_event()
   p.terminate()
   break
derHugo
  • 3,306
  • 5
  • 30
  • 49
Mario
  • 11
  • 1
  • In the above script the following lines are supposed to be comments only. They need to be deleted OR commented with a #. original p = subprocess.Popen('gnome-screensaver-command -a'.split()) changed – Mario Sep 13 '17 at 23:23
  • Lines 27,28,29 and 30. Sorry, not used to the formatting in the comment section. Usually I do not post. But this time I thought this might help. – Mario Sep 13 '17 at 23:34
0

I know that xscreensaver is not exactly blank screen, but may be of some help:

xscreensaver-command -activate  

or via ssh

DISPLAY=:0 xscreensaver-command -activate

The same way deactivate:

DISPLAY=:0 xscreensaver-command -deactivate

or

export DISPLAY=:0 
xscreensaver-command -activate
xscreensaver-command -deactivate

Enter password after xscreensaver via ssh:

DISPLAY=:0 xdotool type Ctrl # wake up from screensaver
   or: DISPLAY=:0 xdotool click 1 
DISPLAY=:0 xdotool type "passwordovich"
DISPLAY=:0 xdotool type Return # Enter 
xerostomus
  • 908
  • 9
  • 20