Color "ls" Output in Terminal

Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Just a quick note to folks with a *nix background who may be using Terminal.app and are frustrated by the lack of color coding on the output. The BSD version of ls, which Mac OS X uses, is a bit different from the Linux versions most of us will be familiar with, and the usual /etc solutions don't work.

To get color output (directories in blue, executables in red, and so on), add the following alias to your .bash_profile:

Code:
alias ls="ls -FG"
The "F" part causes it to add slashes to the directories it lists, and the "G" part enables the color coding per the above.

...and who said the command line wasn't obvious?? :dive:
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
Or, you can add the following to your .bashrc file:


export CLICOLOR='true'
export LSCOLORS="gxfxcxdxbxegedabagacad"

My LSCOLORS= changes a couple of colors which were hard to see on my black background. You dont necessarily have to add that part.
Always more than one way to do something.

Edit: just noticed my ls alias has a g in it too:
alias l='ls -lagh'
try both.
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Thanks cradom. Can you break down the "alphabet soup" in the LSCOLORS var and explain the parts? Thanks!
 
Joined
Jun 6, 2006
Messages
1,153
Reaction score
94
Points
48
Your Mac's Specs
MacBook 2.0GHz White, 512MB RAM, 60GB HDD
You can find out more about LSCOLORS (and all the other environment variables ls reads) by typing:

man ls

You can search within the page by pressing / then typing the search.
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
Straight from "man ls":

The value of this variable describes what color to use
for which attribute when colors are enabled with
CLICOLOR. This string is a concatenation of pairs of the
format fb, where f is the foreground color and b is the
background color.

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

The default is "exfxcxdxbxegedabagacad", i.e. blue fore-
ground and default background for regular directories,
black foreground and red background for setuid executa-
bles, etc.
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Thanks cradom - I should have thought of that!

Tried to give you rep, but it said I had to spread some more around...

oh well, virtual rep!!! Thanks again.
 
OP
mac57
Joined
Apr 29, 2006
Messages
4,576
Reaction score
378
Points
83
Location
St. Somewhere
Your Mac's Specs
Mac Studio, M1 Max, 32 GB RAM, 2 TB SSD
Thanks cradom!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top