Displaying ls in color

How do I get ls to display in color?

By default, the GUI terminals and console shell prompt display files in various contextual colors. However, you may have to add color to the ls command if, for example you are logged into a machine that does not support colored directory listings by default. If this is the case, just include the --color option. For example:

ls -al --color /etc 

Some users feel that adding --color does more than add a splash of color; it gives a clue about the types of files in a directory. For example, directories might all be a royal blue, program files would be green, and so on.

Displaying the listing in color all the time involves a little more work. You will need to add one line to the .bashrc file in your home directory. The .bashrc file is used by your shell when you login. Make sure you are in your /home/login directory and copy the .bashrc file, keeping it in the same directory, but with a name like .bashrc2.

cp .bashrc .bashrc2 

If you make a mistake or have trouble, you can replace your .bashrc file by typing:

cp .bashrc2 .bashrc

at the shell prompt.

Open the .bashrc file with your favorite text editor. For example, you could type pico .bashrc at the command line to open the file. You should see something like this:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

Under the line # User specific aliases and functions type:

alias ls="ls -al --color"

Make sure to write your changes to the file and save them. To make the change work immediately, run the source command to the .bashrc file with the following command:

source .bashrc