1

Why do I lose ls' colors when I ssh to a server?

I would like those colors to be preserved. Is this possible? Should one do something on the server side?

slhck
  • 223,558
  • 70
  • 607
  • 592
MEM
  • 1,297
  • 5
  • 17
  • 29
  • 1
    Does it work when you run `ls -G`? Does the server's shell have `CLICOLOR` and `LSCOLORS` set? (i.e. `echo $LSCOLORS`) – slhck May 20 '12 at 15:31
  • ls -G don't show colors. If I do ls --color I get some. I don't know if the server shell as CLICOLOR and LSCOLORS set. If I echo CLICOLOR and LSCOLORS I got an empty line with nothing displayed. – MEM May 20 '12 at 15:36

1 Answers1

2

The server doesn't use a colored ls command by default.

You can alias your ls command to always use colors in one of the server's shell configuration files (e.g. ~/.bashrc) with the --color=auto option.

alias ls='ls --color=auto'

Some additional remarks:

  • If the server runs Linux, the above should be enough to get colors working. You can use an LSCOLORS generator to manually specify the colors in a shell configuration file by adding:

    export LS_COLORS=…
    
  • If the server runs BSD / OS X, you additionally need the following for ls to automatically show colors (you then don't even need to specify an alias):

    export CLICOLORS=1
    

    Also, here it's not LS_COLORS, but LSCOLORS, and the syntax is different (see the LSCOLORS generator output).

    export LSCOLORS=…
    
Riking
  • 3,333
  • 3
  • 15
  • 16
slhck
  • 223,558
  • 70
  • 607
  • 592
  • Thanks. I believe I have no write access but, I'm using iterm2 with solarize. If I do ls --color what colors will it use ? Can we do something like export TERM =xterm-color or we can't do this since this is on our remote machine? – MEM May 20 '12 at 15:47
  • 1
    It'll use the default colors specified on that machine. You can try changing the meaning of colors in iTerm's preferences though. – slhck May 20 '12 at 15:49