How to enable colorized output for ls command in MacOS X Terminal

I am new to macOS or Apple OS X. How do I enable colorized output for my ls command on Apple Mac OS X just like the ones that shown on my Ubuntu Linux server? How do I configure Mac OS X Terminal app to have color ls output?

You can enable colorized output by passing the -G option to ls command on Apple Mac OS X or FreeBSD operating system. You don’t have to install anything special. Just pass the -G option to the ls command to enable colorized output on Unix box.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements macOS latest or macOS X with bash/zsh
Est. reading time 2m

Mac OS X color ls output option

Open the terminal application and simply type the following command:
$ ls -G

Fig,01: Apple macOS/OS X ls command in action when enable colorized output

Fig,01: OS X ls command in action

Configure ~/.bashrc or ~/.bash_profile to display colorful ls command

When bash is your login shell, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile file in that order. When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc. Hence you must add commands to ~/.bash_profile.

Want to enable colorized output permanently? You need to add the following command in the ~/.bashrc or ~/.bash_profile file:
$ vi ~/.bashrc
$ vi ~/.bash_profile
Append the following alias:

alias ls='ls -G'
alias ll='ls -lG'

Save and close the file. Source the changes immediately:
$ source ~/.bashrc
$ source ~/.bash_profile
Test it:
$ ls
$ ll

How do I skip colorful ls command output temporarily?

Simply run the ls command as follows:
$ \ls
$ \ls -l

The -G option is equivalent to defining CLICOLOR in the environment. The ls command supports the following environment variables:

  1. CLICOLOR – Use ANSI color sequences to distinguish file types.
  2. LSCOLORS – The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR

Just type the following command to enable colorized output for the ls command:

export CLICOLOR=1
## better add to your ~/.bashrc or ~/.bash_profile ##
echo 'export CLICOLOR=1' >> ~/.bashrc

Understanding LSCOLORS values

You can define color for each attribute with the help of LSCOLORS, 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 default value is:



ls Attribute Foreground color Background color
directory e x
symbolic f x
socket c x
pipe d x
executable b x
block e g
character e d
executable a b
executable a g
directory a c
directory a d

The color and their code values are as follows:

Code Meaning (Color)
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

You can now customize it as per your need in ~/.bashrc:

export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

A note about zsh

The latest version of macOS comes with zsh instead of bash. Hence the syntax is as follows and need to append into your ~/.zshrc file:

# zsh example #
echo 'alias ls='ls -G' >> ~/.zshrc
echo 'alias ll='ls -lG' >> ~/.zshrc


You learned How to configure Mac OS Unix terminal to have colored output with the ls command. See ls command man page documenation or read it offline by typing the following ls command:
$ man ls
$ man bash
$ man zsh

This entry is 1 of 5 in the Coloring Outputs in the CLI Apps Tutorial series. Keep reading the rest of the series:
  1. How to enable colorized output for ls command in MacOS X Terminal
  2. How To Turn On/Off Colors For ls Command In Bash On a Linux/Unix
  3. Turn off color in Linux terminal/bash session
  4. Turn On or Off Color Syntax Highlighting In vi or vim Editor
  5. BASH Shell: Change The Color of My Shell Prompt Under Linux or UNIX

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • Fred Jan 20, 2016 @ 18:49

    You can use oh-my-zsh ( and use themes ( too, it’s nice setup with a lot of customizations possible !

    • Sherif Abdalla Jun 11, 2016 @ 12:06

      Thank You

  • Ryan Jan 9, 2017 @ 16:53

    Thanks for this write-up.

    One problem I’m having is that after I follow all the steps and get my text color to change, when I open up a new iterm2 window I lose all the settings. Is there any way to save these CLICOLOR settings?

  • Bharath Aug 21, 2020 @ 20:22

    Once you add & compile ~/.bash_profile file, it will be permanent for all sessions.

    Edit using: vi ~/.bash_profile
    Add the lines and Save.

    Compile using : . ~/.bash_profile

  • Vincent Beers Oct 30, 2020 @ 11:41

    This is cool but .bashrc seems to be ignored on my Macbook for whatever reason. You can also drop it into ~/.bash_profile if that’s the case.

    • 🐧 Vivek Gite Oct 30, 2020 @ 12:57

      Thanks, I updated page to include ~/.bash_profile too. Are you using zsh or bash?

  • Christian E Mar 9, 2021 @ 21:32

    I had this problem as well, and I am using bash 5.1. I just added “source $HOME/.bashrc” to ~/.bash_profile

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum