Tuesday, 12 November 2013

Making "ls" command display color

In an effort to make a terminal in OS X behave more like a terminal would in linux this quick tutorial will make the command "ls" always display color when displaying directories content. This is helpful for quickly identifying what type of files we're dealing with, and generally just makes using the terminal more visually appearing.

Prerequisites

Before attempting this tutorial you'll need to have coreutils installed.

This tutorial was done with the following versions:
  • Mavericks (10.9) 
  • GNU coreutils 8.21

Installation

1. Enter the following in a terminal
echo alias ls="'ls --color'" >> ~/.bash_profile
Note the double quotation marks. These are needed otherwise they're ignored by the echo command.


An easy 1-liner

The alias command tells the shell to run an alternative command in place of a string, in this case, it's running "ls --color" everything the string "ls" is entered. The echo command redirecting into the .bash_profile file just confirms that the shell runs this command every time it's started.

2. Restart the terminal

3. Perform the command to ensure it has worked.

ls

Glorious Color 

End Notes

Check out some other tutorials about diving into the terminal side of things in OS X.

No comments:

Post a Comment