60

Can I turn off my laptop monitor manually and instantly with just a click or a simple terminal command? I just want to turn off my monitor not locking my machine. There is no dedicated turn off monitor button on my machine.

muru
  • 197,895
  • 55
  • 485
  • 740
Nur
  • 4,081

6 Answers6

74

You can by using the preferences command for X server (http://systembash.com/content/how-to-turn-off-your-monitor-via-command-line-in-ubuntu/)

  • To turn off the monitor $ xset dpms force off
  • To turn on the monitor $ xset dpms force on

Pressing a key or moving the mouse will also switch the monitor on if it has been turned off. You can assign the command to a key if you like using shortcuts.

David Ashford
  • 17,278
  • 1
    It works, thanks.. I'm just wondering, can I make it to slowly fade off just like when my computer about to sleep? – Nur Feb 12 '13 at 17:25
  • It would be nice @DavidAshford – Nur Feb 13 '13 at 03:29
  • It doesn't look like xset has the option to slowly fade – David Ashford Feb 13 '13 at 12:44
  • Well it's fine, power saving is what I want, thanks anyway.. – Nur Feb 28 '13 at 03:20
  • 4
    Is there a way to use this commant with locking my screen? When I lock my screen my monitors don't turn off, just go black. I want to save power by turning them off while also locking my session. Any ideas? – Felipe Sep 18 '13 at 19:15
  • 3
    +1; Just a note that this solution isn't unity specific and you can happily use it on any DE. – mreq Oct 29 '13 at 13:07
  • Is there a command that monitor will only turn on when there's a keypress – user Jan 27 '14 at 12:48
  • @Felipe to lock the screen you can use: gnome-screensaver-command -l (or to do both: gnome-screensaver-command -l; xset dpms force off – Tobias J Apr 18 '14 at 03:03
  • 4
    xset dpms force standby seems to be more reliable and doesn't need the sleep 1 ; xset dpms force off trick. – Alan Thompson Sep 17 '15 at 03:59
  • 1
    Is there any way to apply this only one of two screens? I have multiple displays setup and would like to turn off only one of them e.g. when I watch a movie… – edison23 Mar 22 '19 at 13:59
  • the command shuts off all monitors (while OP asks specifically about laptop monitor), maybe you could mention this more precisely in your answer? thanks! – Matifou Jan 13 '21 at 09:46
27

To add on to the other answer, I found that when I entered xset dpms force off and pressed the Enter key, my screen would turn off and turn on again. By running the command below, I was able to get the screen to turn off without turning on.

sleep 3; xset dpms force off
I Like to Code
  • 609
  • 2
  • 8
  • 12
8

Just to add more options... You can run

xrandr --output <DISPLAY_NAME> --brightness 0

To determine your display name, simply runxrandr. It will provide you with information on connected displays, so you can actually turn on and off any of them

Beware though, after running this command, you won't be able to turn your screen on by moving your mouse or using a keyboard. You will have to either use second monitor or blindly type

xrandr --output <DISPLAY_NAME> --brightness 1

So, X RandR provides you with better control over your screens, but it does what it does. It can also be used for other things, like changing resolution, orientation, rate, etc. It is also very easy to run it inside scripts. If you want, you can write a script to make your screen nicely fade to black. Brightness parameter can take fractions

More on X RandR

Example of X RandR script, bind to Fn keys

  • 1
    Note that --brightness option doesn't actually affect hardware, it only colorizes screen in such way that it becomes dark. Quote from the manual on --brightness option: However, this is a software only modification, if your hardware has support to actually change the brightness, you will probably prefer to use xbacklight. – Sergiy Kolodyazhnyy Dec 06 '17 at 19:13
  • That's also true – Hasan Ammori Mar 15 '18 at 14:03
1

In Ubuntu 18.04, dpms not working properly with GNOME Wayland

$ xset -q

DPMS (Energy Star):
Display is not capable of DPMS

You can try the command below,
to turn off monitor:

busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 1

To turn on monitor:

busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 0

It works for me.

(Source)

eR_
  • 180
0

To add to the accepted answer:

If you want to do this remotely over an SSH session, you’ll need to specify the DISPLAY number, e.g.,

DISPLAY=:1 xset dpms force off

If you want to do it for the login screen,

sudo -u gdm env XAUTHORITY=/run/user/$(id -u gdm)/gdm/Xauthority DISPLAY=:0 xset dpms force off

Without the XAUTHORITY bit you’ll get the mysterious error

No protocol specified
xset:  unable to open display ":0"

How did I find that?

In general, if some program is using the display, you can figure out how it’s talking to the display server by looking at its environment variables:

$ ps aux | grep gd[m]
…
gdm         1643  0.1  0.2 3784328 164396 tty1   Sl+  08:59   0:01 /usr/bin/gnome-shell
…
$ sudo cat /proc/1643/environ | tr '\0' '\n'
…
DISPLAY=:0
…
XAUTHORITY=/run/user/126/gdm/Xauthority
…

I happened to recognize these specific environment variables as critical, but in a pinch you could use binary search to narrow down the relevant ones. Try running xset with all the environment variables copied over, and if that works, comment out half of them to see if it still works without, and so on.

andrew
  • 221
0

I found the xset dpms force off command works well. However, when assigning a hot key to this command, I ran into trouble: my screen would turn off and back on again.

I found the reason for this was the hot key combo I was using for no particular reason. I discovered the hot key combo "Mod2+Mod4+Super+Hyper+Left shift" assigned to the xset dpms force off command turns the screen off and the screen will not turn on again until a key is pressed or the mouse is used. Exactly what I wanted! That hot key combo is simply the Super (Windows key) used in conjunction with the left shift key. I'm running Ubuntu 16.04 and this is working on my systems.

Zanna
  • 70,465