Turn off monitor using command line
Solution 1
To turn off monitor in console, the command is the following:
sudo vbetool dpms off
To regain control of the console on pressing Enter key, I suggest
sudo sh -c 'vbetool dpms off; read ans; vbetool dpms on'
Solution 2
Try these commands...
To Turn Off:
xset -display :0.0 dpms force off
To Turn On:
xset -display :0.0 dpms force on
If your display turns off and then immediately back on then try the following which adds a delay of 1 second before turning the screen off. This give a chance for all events to be processed by the X server before turning the display off.
sleep 1 && xset -display :0.0 dpms force off
Solution 3
The xset
command mentioned in other answers will turn off all the monitors if you have multiple monitor setup. However if you want turn off only one or some of the monitor you should use xrandr
.
First run xrandr -q
command, which will list all the monitors and its current display settings. At the start of each monitor details you will find monitor name set by the system. You have to keep track of that.
I have two monitors (one is connected to DVI port and other to VGA port) and when I run the command I see this:
Screen 0: minimum 320 x 200, current 1360 x 768, maximum 2726 x 2726
DFP1 connected 1360x768+0+0 (normal left inverted right x axis y axis) 304mm x 228mm
1360x768 59.7*+
... (more details are shown here, but I have hidden it)
CRT1 connected 1360x768+0+0 (normal left inverted right x axis y axis) 410mm x 230mm
1360x768 59.8*+ 60.0
... (more details are shown here, but I have hidden it)
In this output, DVI port connected monitor is labelled as DFP1
and other one as CRT1
. So if I want turn off the secondary monitor(i.e., CRT1
) I have run this command:
xrandr --output CRT1 --off
if you want switch on that monitor again then you have run this command:
xrandr --output CRT1 --auto
Solution 4
I've just installed Ubuntu Server 18.04.1 (no GUI, X, nor anything graphical), and after breaking my back last night trying to turn off the screen I finally found the magic command:
setterm --blank 1
After executing the command the screen will turn off automatically every minute (if idle).
And even better, if you want the command to be executed automatically at boot, you can add it to the GRUB commandline, to do so we have to edit the next file:
sudo nano /etc/default/grub
Once there, just add consoleblank=60
to GRUB_CMDLINE_DEFAULT
, it should look like this:
GRUB_CMDLINE_LINUX_DEFAULT="quiet consoleblank=60"
Then close the file and save it, after that just run sudo update-grub
and voila, every time you boot the screen will turn off automatically every 60 sec. (again, if idle).
And this way (adding the consoleblank to the GRUB) works even from remote terminals (ssh).
Enjoy! (again)
Solution 5
If you have multiple monitors use this:
Turning off your second monitor:
(Assuming CRT-0 is your left monitor and CRT-1 is your right monitor)
xrandr --output CRT-1 --off
Turning on your second monitor:
xrandr --output CRT-1 --right-of CRT-0 --auto
This way xrandr knows not to duplicate the first screen.
Related videos on Youtube
Andrew
Updated on September 18, 2022Comments
-
Andrew over 1 year
I have this code:
NSString *hString = [NSString stringWithFormat:@"%d", (h * 100)]; HField.text = hString;
H is 0.721.
HField.text now reads:
1073741824
Any ideas why this isn't giving me 72?
-
Andrew almost 13 yearsThis works, except it now returns it as a float. Is there a way to do this same thing but return it as an integer instead?
-
Danny Staple over 12 yearsYou probably then want to alias this lot to something handy.
-
David Clarke about 10 yearsvbetool is available via
sudo apt-get install vbetool
-
ThiagoPonte about 9 yearsI have 3 Monitors, 1 VGA, 1 DVI and 1 HDMI. When i ran: xrandr --output VGA1 --auto, it turned the VGA on, but it cloned the DVI monitor.
-
Harshith J.V. about 9 yearsHmm strange. Try --on instead of --auto
-
Nishant over 7 years@HarshithJ.V. this is a good answer! Its better than the
xset
because xset turns on if you just press the touchpad etc. Btw hope you remember me from your previous company :-) -
ThorSummoner over 7 yearsI was testing this, turning off a screen this way is more like disabling it, eg, the screen is still powered on. Its just not used. The
--off
'd screen cannot be turned back on with the screen's power button (because its still on / was never off). It also messed with my desktop display settings, (from extended desktop to mirrored displays). If this was done to turn both displays off, I'm not sure it would be easy to turn them back on without logging in to TTY and clearing the monitors.xml file wherever it is. The more you know. -
golimar about 7 yearsIn my case this command really turned the display off and not the
xset
one -
Harshith J.V. about 7 years@Nishant Thanks for compliments. Strangely I don't remember you. Please ping me on any other social media as we can't chat over as its against the rules.
-
Karl Morrison over 6 yearsHow do I know which screen is which
-
stiemannkj1 over 6 yearsThe following worked for me (also partially inspired by @enzotib's answer):
xset -display $DISPLAY dpms force off; read temp; xset -display $DISPLAY dpms force on
-
Zmart over 6 yearsBe careful with this. I'm unable to turn my monitor back on with a test machine after issuing
force off
-
Zmart over 6 yearsUpdate: Pulling out and replugging all cables (including power) on the monitor has remedied the situation.
-
haytham-med haytham over 6 yearsIf you got crtc error, then type "chvt 7" before xrandr command, so that it reads "chvt 7 && xrandr -d :0 --output eDP1 --auto"
-
haytham-med haytham over 6 yearsTo save xrandr settings even after relogging, so that you won't get a blank screen, you need to go to display settings in kde then set the primary output in size and orientation tab.
-
danba about 6 yearsStrangely enough the command turns off 2 of 3 displays, the third remaining white for a while before having the machine reboot on its own if the command was executed over ssh.
-
andras.tim about 6 years@enzotib, I clicked accidentally to downvote, sorry. Please edit a bit the answer to I can remove the downvote.
-
andras.tim about 6 years@enzotib me too ;)
-
ozgrozer about 6 years@enzotib how can i turn on monitor pressing any key but without your second command? is there any settings for that? after i turn off the monitor, i can't see what i type.
-
Olaini Lature over 5 yearsExecuting the above command I get: "setterm: terminal xterm-256color does not support --blank". What can be wrong?
-
AxeAR over 5 yearsAre you trying from a remote session?
-
AxeAR almost 5 years@zx485 Check out the updated answer, now you can make the screen turn off from a remote session. I'm sure this will solve your problem
-
Andy Forceno over 4 yearsDoesn't work for me running Ubuntu Server 18.04. It appears to do nothing.
-
Louis Gagnon over 4 yearsthank you for your answer, I would only add that (as in the case of @ThiagoPonte)
xrandr --output DP-5 --auto --right-of CRT1
allows to turn back on the monitor without cloning (replace --right-of with whatever your setup is) -
JohnEye about 4 yearsThis seems to completely freeze NixOS
-
pinkeen almost 4 yearsJust what I was looking for! This is usually included by default in most distros but not server-centric ones like proxmox. Works like a charm.
-
pinkeen almost 4 yearsYou can do this remotely via
setterm -term linux -blank < /dev/tty1
. The commandwho
shows which tty's users are currently logged into. You can also "turn off the screen" so it doesn't react to keys viasetterm -blank force
and reverse it withsetterm -blank poke
. -
pinkeen almost 4 yearsCaution! The value passed to
setterm --blank
is minutes not seconds. I was scratching my head for a while until decided to read TFM. -
Michael Litvin over 3 yearsI added
sleep 1;
in the beginning, as otherwise the monitor would immediately turn back on. -
Tino about 3 yearsUbuntu 20.04 LTS does not work:
server does not have extension for dpms option
. Blanking via keyboard shortcut (Fn+F6 in my case) works (a bit unreliable, releasing Fn often unblanks screen again). But I need a solution which works viassh
when the Laptop's keyboard is out of reach. (It's really annoying if you wake up in bed because the Laptop lights the room. Just a short voice command could invokessh
to stop the Laptop burning! Note that I disable screensavers on consoles, as there is only one thing which is even more annoying than wrong time console blanking: CapsLock!) -
Tino about 3 yearsUbuntu 20.04 Me Too, but I need something from commandline. On my Acer
xset dpms force off
does not work.chvt 2 && setsid sh -c 'TERM=linux setterm --blank force <>/dev/tty2'
(run asroot
viassh
) works, though, but often X11 crashes doing so, rendering screen+keyboard dead. In that case, networkmanager seems to be unable to keep network connections alive, so the machine is neither dead nor alive afterwards. All you can do is a long press of the power button. Checkmate. -
Tino about 3 yearsUbuntu 20.04 LTS:
vbetool dpms off
does not work and saysmmap /dev/zero: Operation not permitted
and thenFailed to initialise LRMI (Linux Real-Mode Interface).
. Tried on X11 as root and viassh
as root and on text console as root. -
robertspierre about 3 yearsIn Ubuntu 20.10 it doesn't work with the same error messages as the ones obtained by @Tino
-
HXH about 3 yearsI confirm that this command doesn't work on Ubuntu server 20.04 @Tino
-
france1 almost 3 yearsdoesn't work with 21.04 too
-
france1 almost 3 yearsX Error of failed request: BadMatch (invalid parameter attributes)
-
france1 almost 3 yearsThe problem is maybe there isn't a function dpms -> ubuntu 21.04 hasn't