Changing terminal color
I would like to know how to change the terminal color, so whenever I run
ls
it will return the name of:
- Directories in red
- Files in blue
- Executable files (those you do
./file
) in light green
How do I do that?
Solution 1:
Usually this is done with
ls -G
Personally I'm using an alias, e.g. in .bash_aliases
which is loaded by .bash_profile
alias ls="ls -G"
However, there's another option, i.e. turning on CLICOLOR
in your shell, e.g. by adding the following to your .bash_profile
export CLICOLOR=1
Solution 2:
See this article "ls, colors, and Terminal.app" to customize the default ls
colors.
Basically, what you need to do is change the value of the LSCOLORS
variable (default is Gxfxcxdxbxegedabagacad
on OS X). Each letter represent a color:
- a = black
- b = red
- c = green
- d = brown
- e = blue
- f = magenta
- g = cyan
- h = grey
- A = dark grey
- B = bold red
- C = bold green
- D = yellow
- E = bold blue
- F = magenta
- G = cyan
- H = white
- x = default
And each two-letter group the foreground and background color for a type of entry.
For example, the first two letters make your directories being shown as Cyan (G
) on a default (x
) background (ie. the background color of your term).
The positions are:
- directory
- symbolic link
- socket
- pipe
- executable
- block device
- character device
- executable with setuid set
- executable with setguid set
- directory writable by others, with sticky bit
- directory writable by others, without sticky bit
So to get the output you asked in your question, setting LSCOLORS
to bxfxcxdxcxegedabagacad
should do the trick, except for the "normal files" colors, which it seems can't be changed this way.
All credits to Jonathan Dance for the blog post linked earlier, most of this answer is copied from it.