I have in my .bashrc

export TERM=xterm-256color

but this cause blinking all colored text (ls --color, in vim etc.) in a Linux console (Ctrl+Alt+F1).

So is there any possibility to recognize in which terminal I am (Linux console or a pseudo-tty) so I can export TERM variable with valid value?


I found alternative solution only:

for vim user (in .vimrc)

set t_Co=256

or for xterm in .Xdefaults (after that xrdb -load .Xdefaults)

XTerm*termName:         xterm-256color

or for screen (.screenrc)

term screen-256color

2 Answers 2


Try not exporting the TERM variable at all. This should be set by the terminal itself to an appropriate value. The linux console should set this to linux, while various X based terminal programs might use the value you set.

You should only set this as an override for when the default values do not work or don't get passed as when SSH'ing to a location that does not recognize your environment.

  • I didn't know that. Still learning. I set 256 color directly from .vimrc.
    – PaulP
    Jul 10, 2011 at 7:28

The console $TERM is linux,[1] so you can construct a test, like so:

if [ "$TERM" = "linux" ]; then

As Caleb notes, setting the environment variable TERM to the type of terminal you would like to emulate is not a good idea.

See http://tldp.org/HOWTO/Text-Terminal-HOWTO-10.html#term_not_for_emulation for details

[1] Since kernel version 1.3.2, the kernel default for the console is TERM=linux.


  • +1 documentation link. Still not reading the documentation enough :D.
    – PaulP
    Jul 10, 2011 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .