QuestionsCategory: BIOSTARHow to enable colors for the ls command
tillodc@nih.gov Staff asked 6 months ago

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

1 Answers
tillodc@nih.gov Staff answered 6 months 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:  https://www.biostarhandbook.com/bash-profile.html#bash-profile. and details about the .bashrc file are given here:  https://www.biostarhandbook.com/terminal-init.html#terminal-init.

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.