QuestionsCategory: BIOSTARHow to enable colors for the ls command Staff asked 3 years ago

How do we get the “ls” command to print out directories/files in different colors?

1 Answers Staff answered 3 years ago

Typing “man ls” shows that -G is the flag that enables colorized output.

So to get it to print out colorized output, we would type “ls -G” in the terminal.

To make the “ls -G” be the default behavior for the ls command,  we can add it as an alias (a shortcut) to our ~/.bashrc file

For the class, the ~/.bashrc file was created in this step of the computer set up instructions: and details about the .bashrc file are given here:

To edit your ~/.bashrc file, open it in a text editor (e.g. nano ~/.bashrc), and add the line:

alias ls=’ls -G’

and save it.

Then either type: “source ~/.bashrc” or open a new terminal to see the changes.