Command line tips - colour your ls output

  • April 10, 2007
  • Avatar for peter
    Peter
    Upfold

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

Home » Articles »