How To Invert Screen Colors in (Ubuntu-based) GNU/Linux Distros

Are your eyes getting tired of reading black text on a white background? Particularly if you read in a dark room? (Now a previous post describes how Evince, a freedom-respecting alternative to Adobe’s bloated PDF reader, can do this automatically with PDF files.)

To have your screen invert colors, all it requires is a one-line script once you download one small package! ). [I can only affirm this is so for those using Debian-based GNU/Linux distros (such as Ubuntu, Linux Mint, etc.).]

It can be done by opening your terminal and typing

xcalib -invert -alter

or, simply,

xcalib -i -a

Your computer may not have the xcalib package installed, and you may be prompted to install it with this code:

sudo apt-get install xcalib

[If you are curious, “sudo” invokes root/superuser/admin privileges, so you will need to use the root password. “apt-get” invokes the package installer that links to Ubuntu software repositories (so you can download it via the internet).]

Then, when it’s all done, try it out. Unfortunately, I cannot get a screenshot of this, as the screenshot does not take into account the inverted colors. Still, it worked for me and should work for you, too! Enjoy!

[UPDATE: For keyboard shortcuts, see below!]

[Author’s note: for more computer tips related to Ubuntu and other Debian-based GNU/Linux distros, check out my Computer Tips category on the right. See, for example, this post on PDF annotation and this post on how to convert JPEG files to PDF and vice versa.]

[Credit goes to the programmers, first, and secondly to the (anonymous) person who shared this information here. If you went to the site I linked, the “#!/bin/bash” should be unnecessary. But if the terminal tells you that your computer does not recognize the commands, try that. Basically, #!/bin/bash tells your computer to use the /bash script language (as opposed to C or other perl). I don’t know too much about it, but I think the default is /sh (shell) and is probably compatible already.]

Keyboard Shortcuts: If you want to assign a keyboard shortcut to invert screen colors, go to where you have Keyboard Shortcuts. Under Cinnamon, for example, you have to go to Keyboards first and then when it opens up, go to the Shortcuts tab and then go to Custom Shortcuts. Add a new shortcut (with the “+” button). The command should be “xcalib -i -a” or “/usr/bin/xcalib -i -a” (“/usr/bin” is where your computer stores your terminal commands in your file system).

Then assign a shortcut (click on “New Accelerator…”). One example is Ctrl+Alt+N (for negative). You can also use Ctrl+Alt+I (for invert). If the shortcut doesn’t work at first, you may have to log out or restart before your computer picks it up.”In Cinnamon, you may be able to get away with refreshing your computer by tying “Alt+F2” and then typing “r” for reset.

Setting Up An Alias (not as efficient as a keyboard shortcut): If you want to set up a permanent alias (textual shortcut), like use “neg” (short for negative) to invert screen colors, first open up the local document that loads instructions for your terminal. To do so, do

sudo gedit ~/.bashrc
OR

sudo nano ~/.bashrc

If you don’t have “gedit” as your text editor, you probably have “pluma” instead (Linux Mint). So replace “gedit” with “pluma.” Otherwise, install “gedit” with “sudo apt-get install gedit.” (UPDATE 2013 Sept 16: “nano” also works well as an in-terminal editor . . . I did not even know of nano at the time of writing this post originally. Oh, and if this doesn’t work, type out the full address “sudo nano /home/user/.bashrc”)

Then, in your text editor, type this line of code

alias neg=’xcalib -invert -alter’

on the first line, save, and then exit.

(REVISED 2013 Sept 16): Then, when you return to the terminal, “update” your bash with your new .bashrc “instructions” file by typing

source ~/.bashrc

Then close your terminal session (using Ctrl+D or typing “exit”) and start a new one (or type “source ~/.bashrc” in terminal to refresh the terminal instructions). You should now be able to type “neg” instead of “xcalib …” to invert colors (though you can also just press the up arrow in terminal to use a previous terminal input).

Advertisements

15 thoughts on “How To Invert Screen Colors in (Ubuntu-based) GNU/Linux Distros

  1. Thanks for the tip. I was able to set up a keyboard shortcut to invert colors on an older Linux Mint. It really helps me to read all the websites with white text on black backgrounds. They really tire my eyes and now I can change them to black text on white. Thanks again.

  2. Pingback: PDF Highlighting & Annotations in GNU/Linux: Okular | Home of Uninterpreted Facts

  3. Big thanks for this tip!
    I was too, tired reading some black pages – and I discovered you can read off a laptop screen “passively” using sun light if you turn off the backlit – but you need white background to be able to read it well – inverting colors will make it great 😀

  4. Pingback: PDF Readers: Free Software Can Be Superior To Non-Free Software | Home of Uninterpreted Facts

  5. It works on my laptop screen so thanks for that! How to make it work on other connected screens I have another monitor connected through DVI.

    • It seems to work on one screen only. So if you turn off built-in laptop display, it will work on your external monitor. If not, you may need to restart with the monitor plugged in.

  6. Hello!
    Thanks a lot for that article! I have a problem though, when i type “sudo apt-get install xcalib” in my terminal it says: “Unable to locate package xcalib”.
    I am sorry, but i am a new user of ubuntu, i have ubuntu 14.04. how can i solve this?

  7. That’s really cool, anyways one issue that I am having with it is, that the command only inverts the colors for one screen, but I have two screens.

    How to address that issue?

    • Good question. No idea. It can work with an external monitor, but only if the built-in screen for the laptop setup I have is disabled. Sorry. I’m not aware of the solution for more than one monitor.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s