Ever wish you had a color ls on AIX - like the one available in linux?
You cant (dont have root privs ) or are not allowed to install (OMG! its open source, everybody panic! ) 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