How can I configure Mac Terminal to have color ls output?

Ask Different Asked by lucius on January 6, 2022

How can I configure Mac Terminal to have color ls output?
I am using MacOS 10.5

11 Answers

For the Catalina version, you need to add export CLICOLOR=1 in ~/.zshrc.

If you want to adjust the colour palette, change colours theme in terminal settings.

Answered by Ebram on January 6, 2022

UPDATE: I switched to Oh my zsh a year back and it is awesome. My favourite theme is lambda-mod and my version of it.

Combining all the answers here is what I use:


function git_color {
  local git_status="$(git status 2> /dev/null)"

  if [[ ! $git_status =~ "working directory clean" ]]; then
    echo -e $COLOR_RED
  elif [[ $git_status =~ "Your branch is ahead of" ]]; then
    echo -e $COLOR_YELLOW
  elif [[ $git_status =~ "nothing to commit" ]]; then
    echo -e $COLOR_GREEN
    echo -e $COLOR_OCHRE

function git_branch {
  local git_status="$(git status 2> /dev/null)"
  local on_branch="On branch ([^${IFS}]*)"
  local on_commit="HEAD detached at ([^${IFS}]*)"

  if [[ $git_status =~ $on_branch ]]; then
    local branch=${BASH_REMATCH[1]}
    echo "($branch)"
  elif [[ $git_status =~ $on_commit ]]; then
    local commit=${BASH_REMATCH[1]}
    echo "($commit)"

PS1+="[$(git_color)]"        # colors git status
PS1+="$(git_branch)"           # prints current branch
export PS1

export LC_ALL=en_US.UTF-8
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
alias ls="ls -Gp"

enter image description here

Answered by Sandjaie Ravi on January 6, 2022

Simply add the following line to ~/.bash_profile file:

export PS1=" [33[34m][email protected] [33[33m]w[33[31m][33[00m] $ "

Preview: enter image description here

This is my preferred colors. You can customize each part of prompt's color by changing m codes (e.g. 34m) which are ANSI color codes.

List of ANSI Color codes:

  • Black: 30m
  • Red: 31m
  • Green: 32m
  • Yellow: 33m
  • Blue: 34m
  • Purple: 35m
  • Cyan: 36m
  • White: 37m

Answered by Shayan Amani on January 6, 2022

I find that all I need really is adding this to my ~/.bash_profile or ~/.bashrc (for Bash) or ~/.zshrc (for Zsh, the new default shell in Catalina)

export CLICOLOR=1

Answered by filype on January 6, 2022

Personally, I'm using Oh My Zsh for adding color and other tricks to my Terminal. I think that is the easiest way.

oh-my-zsh is an open source, community-driven framework for managing your Zsh configuration.

It comes bundled with a ton of helpful functions, helpers, plugins, themes, and a few things that make you shout…

enter image description here

Answered by StrawHara on January 6, 2022

Forget all those decades-old cryptic codes for gosh sakes, use the built in Terminal --> Preferences... Settings pane to set the default skin, and edit the ANSI colors to your liking. You can set the font, too. I prefer Menlo 12pt. This is how any regular Joe can do it, and avoid all the crazy command-line, unix-esque way of doing things as other posters have suggested.

Answered by Geoff Hoffman on January 6, 2022

Also you can customize the prompt color (and its format) by adding:

PS1='[e[0;33m]h:W u$[e[m] '

to ~/.bash_profile or ~/.profile file. Where 0;33 is regular yellow which looks nice in my black/semitransparent terminal window.

Here is a full list of colors and their explanations:

My awesome terminal window

Answered by nacho4d on January 6, 2022

Another option is to use the GNU ls which is part of the 'coreutils' program.

You can get it via Rudix or Homebrew (brew info coreutils)or Macports or Fink. That might be preferable to using a "Mac OS X-only" solution if you use the same shell config files on different systems, or are already familiar with GNU ls.

Answered by TJ Luoma on January 6, 2022

If you want a readable Mac OS X Terminal color scheme, you may want to look into this:

I've been using this for over a year now, and I might not be able to function without it!

Here's an updated link:

Answered by Jeff on January 6, 2022





and add the following line to simply enable color output via ls:

export CLICOLOR=1

To customize the coloring shown by ls you can optionally add this variable, LSCOLORS.


  • Default

    export LSCOLORS=ExFxCxDxBxegedabagacad
  • You can use this if you are using a black background

    export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
  • If you'd like to mimic the colors of a typical Linux terminal:

    export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd

Once you've add the above to either ~/.bash_profile or ~/.profile you can either logout/login or source the file in your shell, for eg:

$ . ~/.bash_profile

NOTE: If you need help in selecting colors to use you can use this online tool called LSCOLORS Generator.

Answered by Bill Szerdy on January 6, 2022

You can add

alias ls='ls -G'

to your ~/.bash_profile to get colored ls output.

Answered by Barry Wark on January 6, 2022

Add your own answers!

Related Questions

Way to logout a user from the command line in OS X 10.9

10  Asked on November 23, 2021 by prateeak-ojha


How to decrease .pdf size without losing quality

9  Asked on November 23, 2021 by michalczukm


Linking between tables in different spreadsheets in Numbers

1  Asked on November 23, 2021 by bori-woulds


Make a global shortcut for a particular app

1  Asked on November 23, 2021 by subtleseeker


How to assign a shortcut key to Control-Command-B?

0  Asked on November 23, 2021 by trung-ta


Mac os not showing after install windows 10 with boot camp

1  Asked on November 19, 2021 by phani-krishna


Mac Pro 2013 A1481 Power Supply Test

0  Asked on November 19, 2021 by raymac


Why doesn’t .bashrc run automatically?

13  Asked on November 17, 2021 by romeovs


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir