Command line tips - colour your ls output

Now some distributions do this for you already, but some don't. What am I talking about? Colouring the output of our great command line friend, ls.

Coloured output from ls can serve many purposes. It can help you to identify directories from files, and it highlights other things, like whether a file is executable or not, whether a symlink is broken or not and many other things.

If you're using GNU ls, which will be a yes probably unless you're using a BSD-based system, then you can get the colour flowing with:

$ ls --color=tty

This is pretty cool, but you don't really want to be typing a lot more every time you need to list a directory contents just to get the colour. For that reason, you can easily set up a bash alias (if bash is your shell, of course).

Open up the .bashrc file in your home folder, and paste this at the bottom:

alias ls='ls --color=tty'

A quick log off and log back on (or just close and reopen your terminal program) should mean your ls now passes with flying colours. Sorry, couldn't resist.

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Command line tips - colour your ls output

Home » Articles » Command line tips - colour your ls output