Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Color-coded 'ls' output UNIX
Some variants of UNIX offer a 'color' option on the ls (directory list)command; OS X doesn't by default.

Chen Jake Zhou has made a version of ls with the color option available on his site.

The program can be downloaded and installed as with any OS X program, but then you'll have to make it executable from a terminal session...
chmod +x ls
...from within the directory where the 'new' ls is installed. You can then test the output by typing...
./ls --color
...from within that same directory. If you like the output, and want to make it permanent, then Read the Rest of this hint for detailed instructions.

To make your new ls the permanent ls, you'll have to do some basic UNIX command line copying and editing as root. Here are the steps, assuming you've successfully installed the new ls into a given directory, and made it executable:

  1. Start a terminal, and login as root:
  2. Change to the bin directory:
    cd /bin
  3. Rename the current ls in case you want it back:
    mv ls ls.bak
  4. Copy the new ls to the bin directory (this assumes you're in /bin, and know the path to the new ls):
    cp /path/to/newls/ls ls
  5. To make the new ls the default, you'll need to edit the tcsh defaults file; the path is /usr/share/init/tcsh/tcsh.defaults. Find this line near the end of the file:
    alias ls 'ls-F' 
    and comment it out by putting a "#" in front of it. Add a new line which reads
    alias ls 'ls --color -F'
  6. Logout and login, and your ls command should now be functioning in color.

    This worked for me, but unfortunately, my terminal window is yellow text on a deep blue background, and I see no easy way to customize the colors of the ls --color command.
  • Currently 2.00 / 5
  You rated: 5 / 5 (10 votes cast)

Color-coded 'ls' output | 6 comments | Create New Account
Click here to return to the 'Color-coded 'ls' output' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
changing the default --color colors
Authored by: tunafat on Jan 12, '02 09:55:00PM

i have been searching long and hard in an attempt to change the dark blue used for directories in ls --color.

downloading the fileutils package from gnu gave me a command, 'dircolors'.

dircolors -b (for bash) or -c (for csh) generates the shell command to set the environment variables for the colors used in ls --color.

the deep blue color used for directories in ls --color is set by the di variable in the LS_COLORS environment variable. i've changed it to di=01;35.

to permanently set this for all shell invocations, you can copy the output generated by dircolors -b into your ~/.bash_profile.

[ Reply to This | # ]
Using Fink is TWICE as easy!
Authored by: noelndj on Mar 30, '02 03:31:58PM

If you are using fink ( and you want color ls output it is much easier than any other method to do "sudo apt-get install fileutils"

I know this has been discussed before, but fink is SO easy to use that I think it would be easier than some other methods. As well it can be erased if you feel it is causing a problem, or you just want it gone.

[ Reply to This | # ]
color ls and OSX 10.2
Authored by: r2d2mac on Sep 06, '02 12:44:42AM

if you upgraded to jaguar and had a working color ls...
you sure saw it's been replaced by a new uncolored one.

to get a very fresh one:


put it in any directory, then point the terminal at it
(type cd and drop the folder icon on the terminal), and
compile the gnu version yourself (Developer package needed):

# tar xzf ./fileutils-4.1.tar.gz
# cd fileutils-4.1
# ./configure
# make
# cp ./src/ls /bin/
# rehash

and you have back a colored version...
note: configure takes a while on a 400mhz g4...

you might as well use a ready installer that i made, if you prefer:
(unpack with stuffit expander and launch)

[ Reply to This | # ]
color ls and OSX 10.2
Authored by: solomone on Nov 16, '02 02:51:44AM
    This worked great!

I tested it first on a dummy machine that I
use for testing and that I wasn't worried about if it blew up but this was

awesome. Mind you I use bash instead of tcsh and I added the following color
instructions to my /etc/profile


and the following instruction to my home directory .profile file
alias ls='ls -aF --color=always'
the arguments a and F are not necessary to turn on the color but without it you
will need to add --color at the end of every ls command you enter at the
command line. truly a pain in the ass if you don't add the alias to your
personal .profile file.

[ Reply to This | # ]

color ls and OSX 10.2
Authored by: czar on Oct 11, '03 09:56:24PM
And now for something completely similar Of course, one wants to use it with the installed (default) shell, tcsh, so, I made it system wide.
cd /etc
sudo pico csh.login
You're now editing the csh.login file, this is the system wide file, I also put system wide aliases in here. add the lines:
setenv LS_COLORS "no=0:fi=36;1:di=31;1:ln=4;33:ex=33;1:*.jpg=35;1:*.jpeg=35;1:*.
alias ls "ls -aFl --color=always"
Note, the setenv LS_COLORS is all one line and ends in a double quote (") I downloaded and installed the modified ls color from earlier in the thread, then, I recalled I had already installed it so, oh well, I did twice the work :). anyways, looks kinda cool with solomon's suggestions, he did most of the work, thanks! -Scott PS Does anyone know if the more command can be made to not kill the color sequences, I've an alias as follows:
alias lsm "ls -aFl | more"
and modified it to read
alias lsm "ls -aFl --color=always | more"
I also tried it w/o the --color=always because the alias to redefine ls is right above it, same result as shown below. When I run the command, I get an icky output (here's a few lines):
ESC[0mtotal 8064
drwxr-xr-x   43 czar     admin        1462 Aug  4 14:30 ESC[31;1m.ESC[0m/
drwxr-xr-x   35 czar     admin        1190 Oct  4 22:06 ESC[31;1m..ESC[0m/
-rwxr-xr-x    1 czar     admin        6148 Aug  4 14:30 ESC[33;1m.DS_StoreESC[0m
-rw-r--r--    1 czar     admin      195126 Jun  1 13:06 ESC[35;
Is this correctable so the output comes out colored as expected? Ideas?

[ Reply to This | # ]
Color-coded 'ls' output
Authored by: einsidan on Oct 20, '09 01:19:04PM
I know this tip is ancient, but since I stumbled on to it, I figured someone else might as well. What I did, and I feel is simpler than what is being suggested here, was simply edit /etc/bashrc, adding the following line to it:

alias ls="ls -G"

Log back on, and bob's your uncle =)

[ Reply to This | # ]