How can you make a bash shell list executable files in a different color than non-executable files?

I've tried editing ~/.bashrc to contain the following line (it's otherwise empty):


But it's not working. What am I doing wrong? I'm working on Mac OS X.


To turn on colour output from the ls command without having to create an alias to ls or download any additional software, add the following to your ~/.bash_profile:

# Terminal colours
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

If you don't like those colours you can use this ls color generator to customize that color list to your liking.

You'll need to do:

source ~/.bash_profile

After making any changes for them to take effect in your existing shell.

| improve this answer | |
  • no, it doesn't help at all – holms Nov 16 '13 at 3:24

The problem is that OS X doesn't have GNU ls; while its ls does support file name coloring, it can only do so by the type of file (file, directory, symlink, device special file, fifo, socket...). Install coreutils from Fink/MacPorts/HomeBrew, then use alias ls='gls --color=auto'.

| improve this answer | |
  • Thanks. I've installed coreutils from MacPorts. Should the alias line be in ~/.bashrc? That's where I've put it, but I'm not seeing any difference. – AP257 Mar 22 '11 at 23:10
  • ~/.bash_aliases may work better. I also found that I needed to run eval $(gdircolors -s) to set it up. – geekosaur Mar 22 '11 at 23:12
  • @AP257: On my Mac, I put aliases into the .bash_profile – Hai Vu Mar 29 '11 at 2:56
  • @Hai Vu: That only works if you never use subshells. – geekosaur Mar 29 '11 at 2:58
  • @geekosaur gdircolors: invalid option -- 's' do you mean --sh ? – Anentropic Jan 15 '13 at 12:44

BSD ls works a bit differently

alias ls='ls -G'

should work.

And this isn't bash coloring, it is ls doing the colorization. When bash does a file list (try echo * in a directory) there is no way to colorize. Typing ls -G would work in any shell, though a shell (like bash) that has aliases makes it easier.

| improve this answer | |

On the Mac, you need to use

export CLICOLOR=1

I put that in the .bash_profile. However, I prefer Rich Homolka's solution to alias ls with -G flag. If you want to customize the colors:

man ls

and search for LSCOLORS

| improve this answer | |

Consider installing brew and using the GNU version of ls and other tools.

Install XCode from the AppStore.

Install Homebrew...

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install coreutils...

brew install coreutils

Add to the bottom of your .profile...

export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
export MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"

I alias ls in my .profile to do colors for everything and a shortcut for full list.

alias ls='ls --color'
alias l='ls -lah'
# -l     use a long listing format
# -a     do not ignore entries starting with .
# -h     with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)

There are a bunch of LS_COLORS options on github.

| improve this answer | |

bash is only a shell, it does not list files. It executes commands, such as ls.

The --color option (and long options in general) is specific to the version of ls from GNU coreutils, which comes with most Linux distributions. On the other hand, Mac OS X has BSD roots and uses the BSD version of ls which does not support colouring.

| improve this answer | |
  • 1
    -1: It does support colouring, just with a different command-line flag: -G. – Wuffers Mar 29 '11 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.