Why do telnet window colors change when I invoke linux commands ?

My Dell Laptop, Intel Core i5 is running Windows 10 Pro 64-bit

Step 1 -  I invoke windows command prompt.  The screen text is White with black background.  That's what I expect.

Step 2  -  I telnet into remote Linux server from my windows computer.  I'm at my home directory.  Screen colors are as expected.

Step 3  -  I invoke Linux command to view contents of my home directory.  The output is displayed in different colors.  Why?  I need colors to remain as expected.

Please see attached.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin MillerCTOCommented:
Check you terminal emulation type, e.g.

echo $TERM

if this is not set or not vt100, try this.

setenv TERM vt100          
TERM=vt100; export TERM    
export TERM=vt100
When connected to the telnet session. Display the terminal type, echo $TERM
If it is anything other Vt100, I,e, ansi, xterm the shell you are using has predefined color schemes.

Do the following
Export TERM=vt100
And your display should revert to your........ Desired view.
nociSoftware EngineerCommented:
The 'ls' command can signal file types using colors so directory entries can be easily distingished by type.
this is done according the LS_COLORS evironment variable

if you want it only once you could use the command:
ls --color=never *

the other option is to remove the LS_COLORS environment variable.
export LS_COLORS=

if you edit or create your  ~/.bashrc (logon script) you make this persistent:

# Bash logon script
# disable ls coloring:
export LS_COLORS=

Open in new window

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dr. KlahnPrincipal Software EngineerCommented:
As noci stated, linux computers think this is a wonderful feature that everyone wants.  That drives me just crazy,.  It is particularly annoying in the logs where all I want to see is plain text.

I think noci's fix above should work for user generated output, but I'm pretty sure it won't disable color diddling in the log files.  That is written right into the file as escape sequences and the only way I know to eliminate it (under Debian / ubuntu) is to make the change below.

To:  Disable escape sequences in boot log
  Edit /lib/lsb/init-functions
    In log_use_fancy_output, force FANCYTTY=0

log_use_fancy_output () {
    case "$FANCYTTY" in
        1|Y|yes|true)   true;;
        *)              false;;

Open in new window

it is as easy to set the TERM=vt100 within .bashrc as it is to redefine LS_COLORS.
The identification of the TERM emulator is the overarching

telnet is an insecure and often should be disabled in favor of an ssh (secure) connection.  The tool used can then pass the setting for the TERM thus avoiding all this..

The "color" representation was added in the newer shells, bash. if your default shell is /bin/sh
the LS_COLOR has no impact

Each shell has its features. pick the shell that suits you and ...

We often are susceptible to the preferences of the admin who creates our account. i.e. when the admin has bash as the preferred shell, and if you do not specify which shell you prefer, when the account gets created bash is the shell you get. Similarly those with csh, ksh, etc.
I include the option for the user to specify their preferred shell, and as long as it is available that is the shell they will have.
naseeamAuthor Commented:
My terminal was set to ansi.

Using export command, I changed it to vt100 but ls command output still has colors.

export LS_COLORS=     was accepted by bash shell but output of ls command still has colors.

export LS_COLORS=   didn't work.  After this command, I echoed $LS_COLORS and the value is empty.  But still output of ls command has colors.

ls --color=never    worked but other commands change colors.  For example, vim .bashrc opens the .bashrc file in vim editor with changed color.  Exiting the editor and typing ls outputs the change colors.
alias ls
this will return info on whether you are actually running /bin/ls or yours is defined as ls --color=auto

The color schemes were added to help coders debug programs as different types have their own color...
change your shell to sh and you Should be set.
there are different enhancements added to the different shells.

TERM vt100 should have the data in vi/vim in a single color....
nociSoftware EngineerCommented:
vi has a different setup for colors ,,, so yes you will find many tools that use a feature called syntax coloring (vi, emacs, ...) if the terminal will handle it.
on my system
export LS_COLORS=

Open in new window

 does work. As that environment variable is used by ls...

btw there is an other workaround for ls:
ls * | cat

Open in new window

(meaning the cat program will receive the input from ls, in that case ls will not produce colors, and the cat program just copies stdin -> stdout.
colors are only shown to a terminal, not to pipelines of files (unless explicitely requested).
naseeamAuthor Commented:
I mostly used windows.  I only have very basic linux knowledge.  Please provide me exact steps to solve this issue.

My shell is bash.  That cannot change.  I don't have permission to modify any administrative or system scripts that run when user logs on to linux.  I have permission to modify scripts in my home directory, like .profile or .bashrc.

Any bash shell command must not change colors.
nociSoftware EngineerCommented:
Try the following, copy & paste the folowing code block in the remote session as a whole.

cat >~/.bashrc <<EOF
# bashrc login script.
export TERM=vt100
alias ls='ls --color=never'
. ~/.bashrc

Open in new window

Now this will not prevent every and all commands of coloring the output as each command may act differently...
ls doesn't look for terminal type
A lot of the commands won't care, if they care then there always is an option to disable it.
man {command} will show the description about the command.
f.e. man ls will tell all the option is has, looking down the OPTIONS section you can notice how the --color argument works... Same for different commands.

either make an alias or maybe there are other provisions to disable colors.
Another option might be use a different terminal emulator like putty (for windows) and setit up for black/white.  black/green or whatever.

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
naseeamAuthor Commented:
noci >  I copy and pasted and it worked.  But it overwrote my .bashrc.  So, I changed my .bashrc to what it was before and I manually added the ls alias to this file.

The only thing is my shell prompt changed to        -bash-4.1$
Is it possible to get my previous shell prompt back        [anaseem@<server><current directory>$
your issue is that bash often aliases ls as 'ls --color=auto'
editing the .bashrc as was posted above, and commenting out (#) or at the buttom running unalias ls

Will do the trick.

in vt100 the editor, vi/vim will no longer display colors.
naseeamAuthor Commented:
Great comments.  

Persistent comments until problem was solved.

Experts were delivering information at my pace.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.