Linux disable screen blanking i.e. preventing screen going blank

by on May 13, 2006 · 20 comments· LAST UPDATED May 13, 2006

in

It is easy to disable screen saver under X window. But when it comes to text based login or terminal you will not find easy way to disable text based power saving mode (i.e. when your screen goes blank after a few minutes).

So how do I disable the blank screen mode, which activated after a few minutes? Answer is use setterm command.

setterm writes to standard output a character string that will invoke the specified terminal capabilities. Where possible terminfo database (terminfo is a data base describing terminals, used by screen-oriented programs and libraries such as ncurses) is consulted to find the string to use.

By default, the Linux kernel will use screen-save option to disable it you need to type command (it turns off monitor VESA powersaving features):

$ setterm -powersave off -blank 0

If it dumps back you with an error that read as follows:

cannot (un)set powersave mode

You need to shutdown X window system and rerun the above command. Better, add following two commands to your ~/.xinitrc file:

setterm -blank 0 -powersave off -powerdown 0
xset s off

Other useful options

This command also supports other useful options:
Resets the terminal to its power on state:

$ setterm -reset

Alternatively, initialize terminal:

$ setterm -initialize

Turns the terminal's cursor on or off:

$ setterm -cursor [on|off]

Turns automatic line-wrapping on or off (virtual consoles only)

$ setterm -linewrap [on|off]

Sets the foreground text color (virtual consoles only):

$ setterm -foreground blue

Sets the background text color (virtual consoles only):

$ setterm -background red

Enables or disables the sending of kernel printk() messages to the console (virtual consoles only). Useful if you get lots message from iptables firewall:

$ setterm -msg [on|off]

I regularly use these (above) options.

See also:

  • Please consult the setterm and terminfo man pages for more information.
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 20 comments… read them below or add one }

1 Graeme September 8, 2006 at 10:36 am

I wouldn’t use “setterm -msg off”, as you don’t get useful panic messages. Rather use “dmesg -n1″, so that you still get panic messages but not all the trivial junk to the console. Otherwise thank you for a useful page

Reply

2 Helge February 20, 2008 at 5:27 pm

Your guide was a great help, however it wasn’t enough for a clean approach on my Ubuntu 7.10 system.

I don’t have an .xinitrc, so instead I put this in ~/.bashrc:
xset s off > /dev/null 2>&1
and this in /etc/rc.local
sh -c 'setterm -blank 0 -powersave off -powerdown 0 /dev/console 2>&1'
This also does not produce errors even though I’m running an X session.

Reply

3 Helge February 21, 2008 at 5:40 pm

Somehow copy-paste screwed up before.
Here’s the code for rc.local:
sh -c 'setterm -blank 0 -powersave off -powerdown 0 /dev/console 2>&1'

Reply

4 Helge February 21, 2008 at 5:43 pm

I’m very sorry to “spam” like this >_<
Figured < was interpreted as an HTML-tag.
Hopefully it should work now:
sh -c 'setterm -blank 0 -powersave off -powerdown 0 < /dev/console > /dev/console 2>&1'

Reply

5 Matt Simmons July 7, 2008 at 1:54 pm

Great tips. Screen blanking used to irritate me on the console, too. Especially for my servers which I KVM into. There’s no screen to burn out, so why should the term go blank?

Anyway, I wanted to add that sometimes I’ll do something dumb, like cat’ing a binary file, and it completely screws the terminal window. The way to recover from that is just the ‘reset’ command. A lot of people probably don’t know that.

Before I learned about it, sometimes I’d be up to 3 or 4 terminals lost to garbage on the screen. Logging out never helped, and I used to have to restart the machine to recover them. ‘reset’ fixed that.

Reply

6 Alejandro Ravera March 4, 2014 at 8:10 pm

Doesn’t ‘clear’ command clear the terminal?

Reply

7 Joe July 22, 2014 at 8:19 pm

Nope, clear will just clear the contents of the screen… reset actually resets the terminal.

Reply

8 Neverb August 26, 2008 at 7:52 am

also you can just execute
echo -e ’33[9;0]33[14;0]’
if your terminal supports CSI-sequences (if you use linux – you may shure that it does)

Reply

9 Neverb August 26, 2008 at 7:53 am

omg, ‘\33[9;0]\33[14;0]‘ i mean

Reply

10 anotheranne March 5, 2010 at 10:09 am

To disable the screen blanking I put the suggested line into /etc/inputrc on my ubuntu server (no .xinitrc)

thanks, I like your pages (and format), they always seem to hit the problem right on the head.

Anne

Reply

11 JS October 7, 2011 at 6:09 am

Thank you so much! This comment saved me much trouble.
I’m somewhat of an ubuntu newbie, and chose to run a distro without a GUI to save resources for my minecraft server =P

Reply

12 Alex November 19, 2014 at 3:20 am

That is a horrible idea! I tried this on a Debian system (which is what Ubuntu is usually built upon) and it disabled my ‘x’ and ‘s’ keys in bash. I would not advise anyone to do this.

Reply

13 David April 29, 2010 at 5:20 pm

How do I make this permanent? I did the lines Helge put up but once I reboot the system, it goes back to blank out the screen after about 15 mins.

I’ve previous turned off acpid and apmd with chkconfig.

I need to have the device load everything and remain with an active screen indefinitely. So far the only thing that lets me do that is this setterm command, however, when I reboot – it goes away.

Reply

14 Andrew McNabb November 11, 2011 at 5:59 pm

To set this behavior permanently, add consoleblank=0 to the kernel command-line.

Reply

15 brainiac October 15, 2013 at 10:36 pm

like that?

$setterm -foreground magenta -store consoleblank=0

Can that keep the settings?

Reply

16 mohamed November 29, 2011 at 8:32 am

i am try to use your command in redhad but it is not work
i already have screensaver in terminal 7 and i try to disable it from another terminal with $ setterm -powersave off -blank 0
i do not get any error but it is not work and screensaver still work
also when i am try to use comman in gui by xset s off it also did not work i not know
i hope anyone could help me please

Reply

17 r May 28, 2012 at 1:51 pm

In case anyone is still interested, there seems to be a “feature” in ktorrent that re-enables dpms. Problem aparently appeared after an update.
Description:
“xset -dpms” is run on startup, so screen doesn’t go blank. “xset -q” confirms this. Then running ktorrent and checking again with “xset -q” and dpms is again enabled, moreover – sometimes it will shut down in 48 seconds, other times in 110, other times in 600.
Source:
I traced the problem to be in ktorrent’s “prevent suspend when torrents are running” option. If you disable this option then starting ktorrent doesn’t mess around with the dpms settings.

I hope this helps someone out there.

Reply

18 r March 5, 2014 at 12:03 pm

It seems I posted this answer to the wrong question. Sorry…

Reply

19 Joe June 2, 2013 at 1:07 am

Thanks a lot for this solution :D NO MORE BLANKING YAY!!!

It’s such a pain in the S!!!
Whoever came up with this BS should be forced to stare at their stupid screen blanking 24/7, hands tied to their chair and all input devices diconnected.
…10 minutes… what a stupid delay anyways. it’s just right to be annoying, bullying and griefing people. Whatever you do…coffee, smoking, toilet you always arrive just in time to see your screen go blank. Oh and every 10 minutes while reading something… awesome, really well thought out. i’m sure that a PhD or two are required to come up with such turn-off-my-screen-for-the-sole-purpose-of-being-a-major-pain-in-the-s crap.

Reply

20 Jonny Trinham October 6, 2014 at 1:55 am

Sorry if I missed this somewhere, but is this command long lasting? Or does it have to be redone after a reboot of the server?

Reply

Leave a Comment

Previous post:

Next post: