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

by n00b_Programmer on May 13, 2006 · 12 comments

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.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 12 comments… read them below or add one }

1 Graeme September 8, 2006

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

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

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

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

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 Neverb August 26, 2008

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

7 Neverb August 26, 2008

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

Reply

8 anotheranne March 5, 2010

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

9 JS October 7, 2011

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

10 David April 29, 2010

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

11 Andrew McNabb November 11, 2011

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

Reply

12 mohamed November 29, 2011

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

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 4 + 2 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: