×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Useful Commands-aix

Color ls script by sbrews
Posted: 19 Apr 07

Ever wish you had a color ls on AIX - like the one available in linux?

You cant (dont have root privs neutral ) or are not allowed to install (OMG! its open source, everybody panic! bugeyed ) the GNU ls?  You might like this script.

This is something I threw together to give me colors.
Once the script is saved, just set up an alias:

alias lsc=/path/to/script

Then to see your files in color:  lsc -la
For longer (more than one screen) listings, pipe to pg - as more messes up the escape color codes.  

One more thing... lsc with no parameters will just list your files the same as a plain old ls would.

use/modify to suit your needs

CODE

#!/bin/ksh
#***************************************************************************
#* Created by: Scott Brewster                                              *
#*       Date: 16-Apr-2007                                                 *
#*   Location: TBD                                                         *
#*                                                                         *
#* Description                                                             *
#* ----------------------------------------------------------------------- *
#* Half an effort to create a color 'ls' script for AIX WITHOUT having to  *
#* install the GNU ls (which does support color).  Lots of room for        *
#* improvement.                                                            *
#*                                                                         *
#*     Date       Modified By     Reason for modification                  *
#* -----------  ----------------  ---------------------------------------- *
#* 16-Apr-2007  Scott Brewster    Created                                  *
#*                                                                         *
#***************************************************************************
#***************************************************************************
#* Check to see if any parameters were passed.  If not, just list files.   *
#***************************************************************************
if [[ $1 = ""  || $(echo $1|cut -b1) = "/" ]]
then
   ls $1
   exit 0
fi

#***************************************************************************
#* Issue ls with parameters, send to a tmp file                            *
#* $1 is any ls parameters - ie -la                                        *
#* $2 may be a directory other than CWD - ie /etc                          *
#* the grep -v is in case this is issued in home dir - we dont want to see *
#* our tmp file since it will be deleted when this script finishes.        *
#***************************************************************************
ls $1 $2 |grep -v $$.tmp >> ${HOME}/$$.tmp

#***************************************************************************
#* Process the file.                                                       *
#* If dir: blue, link: light blue, char/block device: inverse blue, white  *
#* socket: red, everything else: no color                                  *
#***************************************************************************
while read LINE
do
  TYPE=$(echo $LINE|cut -b1)
  case $TYPE in
           d) echo "\033[1;34m$LINE\033[0m" ;;
           l) echo "\033[1;36m$LINE\033[0m" ;;
        [cb]) echo "\033[44;37m$LINE\033[0m" ;;
           s) echo "\033[0;31m$LINE\033[0m" ;;
           -) if [[ $(echo $LINE|cut -b4) = "x" || \
                    $(echo $LINE|cut -b7) = "x" || \
                    $(echo $LINE|cut -b10) = "x" ]]
              then
                echo "\033[32m$LINE\033[0m"
              else
                echo "\033[0m$LINE"
              fi ;;
           *) echo "\033[0m$LINE" ;;
  esac
done < ${HOME}/$$.tmp

#***************************************************************************
#* Clean up the tmp file                                                   *
#***************************************************************************
rm ${HOME}/$$.tmp

Back to IBM: AIX FAQ Index
Back to IBM: AIX Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close