By Manny Fernandez

January 9, 2020

Adding Color to Your macOS “ls” Output

I am big on having colors on my cli.  It makes things very easy to identify when things are amiss.  I have this on my SecureCRT implementation.  Here is an easy way to show colors on your ls output on your macOS.

Before

Here is the default way iTerm2 displays the output.

2020-01-09_12-40-00.png

Command to Change

Shell out to your terminal.

vi ~/.bashrc

Once you edit the file, hit i to enter the edit mode.

​add alias ls="ls -G"

2020-01-09_12-47-28.png

After

As you can see below, the blue text is very difficult to read against my dark background.

2020-01-09_12-46-55.png

Customization

Since that Dark Blue is unacceptable for my use, here is how to customize it.

For this, I will edit the

vi ~/.bash_profile

In there we will enter

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

2020-01-09_13-23-49.png

The color designators are as follows:

a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background

Note that the above are standard ANSI colors. The actual display may
differ depending on the color capabilities of the terminal in use.

The order of the attributes are as follows:

1. directory
2. symbolic link
3. socket
4. pipe
5. executable
6. block special
7. character special
8. executable with setuid bit set
9. executable with setgid bit set
10. directory writable to others, with sticky bit
11. directory writable to others, without sticky bit

In my example, value LSCOLORS=GxFxCxDxBxegedabagaced, means directory = Gx (1st Position) set to (bold cyan foreground and default background). So Capital G = Bold Cyan and lowercase x = the default background

Outcome

2020-01-09_13-34-15.png

So on this output, I moved to my Desktop folder so we could see some files and some fake executable files.

  1. Directory colors are Cyan in bold
  2. We see standard files shown in white
  3. Files with the x attribute are shown in red.

Hope this helps

 

Recent posts