OpenBSD Journal

Add Color to Your Terminal

Contributed by jason on from the double-rainbow-omg dept.

Mark Solocinski has kindly given us permission to reprint one of his recent blog posts. This is a nice quick tip for getting color "ls" output in your terminal.

Want to add some color to your shell environment? FreeBSD and most Linux distros have color options included in the "ls" utility by default. OpenBSD doesn’t but but it’s very easy to add. We just need to install the colorls package (sysutils/colorls in ports).

# pkg_add colorls

Colorls works exactly the same as regular "ls". To get the color option you just need to use the -G option. If you want it to replace "ls" for regular work you can create an alias in your favorite shell’s environment file. The output for file and directory listings will now have a different color for different types of files.

White = regular file
Purple = directory
Red = executable file
Magenta = symbolic link
White highlight = Set Group ID enabled
Red highlight = Set User ID enabled
Yellow highlight = Sticky bit enabled

Enjoy! Almost as good as getting the window seat at work.

(Comments are closed)


Comments
  1. By Bryan Brake (brakeb) on

    I am glad OpenBSD doesn't have this 'feature'... it's always the first thing I kill when I get on a Linux box. The colors are annoying and not worth hassle.

    Comments
    1. By bnadland (bnadland) on

      > I am glad OpenBSD doesn't have this 'feature'... it's always the first thing I kill when I get on a Linux box.The colors are annoying and not worth hassle.

      Personally, it is one of the early things I install on a fresh OpenBSD box. I prefer to see at a glance what is a directory and what is not.

      But, as with my Syntax Highlighting in $EDITOR, I prefer not to much distraction so I export LSCOLORS=Aaxxxxxxxxxxxxxxxxxxxx in my .profile to only show the directories (Aa) in a different color and keep all else (x..x) at the terminal default.

      Comments
      1. By Anonymous Coward (bnadland) on

        > [...]
        > But, as with my Syntax Highlighting in $EDITOR, I prefer not to much distraction so I export LSCOLORS=Aaxxxxxxxxxxxxxxxxxxxx in my .profile to only show the directories (Aa) in a different color and keep all else (x..x) at the terminal default.

        I meant LSCOLORS=AaxxxxxxxxxxxxxxxxAaAa

        Comments
        1. By Bryan Brake (brakeb) on

          > > [...]
          > > But, as with my Syntax Highlighting in $EDITOR, I prefer not to much distraction so I export LSCOLORS=Aaxxxxxxxxxxxxxxxxxxxx in my .profile to only show the directories (Aa) in a different color and keep all else (x..x) at the terminal default.
          >
          > I meant LSCOLORS=AaxxxxxxxxxxxxxxxxAaAa
          >
          >

          Or you could just 'ls -la' and look for a 'd' at the beginning of every line



          -rw-r--r-- 1 root wheel 578B Nov 9 02:44 .cshrc
          -rw-r--r-- 1 root wheel 411B Nov 9 02:44 .profile
          drwxr-xr-x 2 root wheel 512B Nov 9 02:44 altroot
          drwxr-xr-x 2 root wheel 1.0K Feb 20 11:21 bin
          -r-xr-xr-x 1 root wheel 43.8K Nov 10 14:48 boot


          I see 2 directories... weird...

      2. By phessler (phessler) on http://theapt.org

        > > I am glad OpenBSD doesn't have this 'feature'... it's always the first thing I kill when I get on a Linux box.The colors are annoying and not worth hassle.
        >
        > Personally, it is one of the early things I install on a fresh OpenBSD box. I prefer to see at a glance what is a directory and what is not.
        >
        > But, as with my Syntax Highlighting in $EDITOR, I prefer not to much distraction so I export LSCOLORS=Aaxxxxxxxxxxxxxxxxxxxx in my .profile to only show the directories (Aa) in a different color and keep all else (x..x) at the terminal default.

        ls -F

             -F      Display a slash (`/') immediately after each pathname that is a
                     directory, an asterisk (`*') after each that is executable, an at
                     sign (`@') after each symbolic link, an equal sign (`=') after
                     each socket, and a vertical bar (`|') after each that is a FIFO.
        

  2. By Bridau Fuzz (bridau) fuzz@imaginatif.org on http://www.imaginatif.org/

    Welcome undeadly into the loonix land.

    Where are the looney tunes ?

    Come on.

    Comments
    1. By jason (jason) on http://undeadly.org/

      Instead of whining why don't you submit some content for us to publish?

      Comments
      1. By Francois Bridau (bridau) on http://www.imaginatif.org/

        > Instead of whining why don't you submit some content for us to publish?


        purple:ports {215} make search key=ls | awk '/color/ && /Path/ { print $0 }'
        Path: devel/ruby-color-tools
        Path: sysutils/colorls
        Path: sysutils/colortail

    2. By Daniel Bolgheroni (dbolgheroni) on

      > Welcome undeadly into the loonix land.
      >
      > Where are the looney tunes ?
      >
      > Come on.

      People whining here doesn't realize this is _an option_. Yes, you can still use your regular 'ls'.

      Comments
      1. By Chris Bennett (chrisbennett) on www.bennettconstruction.us

        > > Welcome undeadly into the loonix land.
        > >
        > > Where are the looney tunes ?
        > >
        > > Come on.
        >
        > People whining here doesn't realize this is _an option_. Yes, you can still use your regular 'ls'.

        Actually, I like nice full displays so I alias ls="colorls -Gla'

        I also find it better to have colors for newbies. But that is also a bad learning curve.

        So instead of typing ls, which is aliased, I tell them to type colorls to get normal ls! SO I can have both! HA!

      2. By Janne Johansson (jj) on http://www.inet6.se

        > > Welcome undeadly into the loonix land.
        > >
        > > Where are the looney tunes ?
        > >
        > > Come on.
        >
        > People whining here doesn't realize this is _an option_. Yes, you can still use your regular 'ls'.

        Since this news item is the first in a while to draw 12 comments, it must mean colorls definately means something for people, hate or love as they may.

        If one post would go "obsd ported to Z5673 zOMG-CPUs that runs infinite loops in 12 minutes and are so fast they need two HALT instructions to stop" noone even posts a "imagine a beowulf cluster of those"-joke, but colorls brings in all the comments. That must really mean something.

  3. By Jona Joachim (jaj) jaj-undeadly@hcl-club.lu on

    Just for the record, to have colors in the console you need:
    export TERM=wsvt25

  4. By Thomas Pfaff (tpfaff) tpfaff@tp76.info on http://www.tp76.info

    For those interested, here's my LSCOLORS

    LSCOLORS="gxxxxxxxcxxxxxxxxxxxxx"

    I'd like to be able to color broken symbolic links but that feature seem to be missing.

Latest Articles

Credits

Copyright © - Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to as well as images and HTML templates were copied from the fabulous original deadly.org with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]