non GNU ls and color on a unix system


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting non GNU ls and color on a unix system
# 1  
Old 05-09-2005
non GNU ls and color on a unix system

Where I work, ls --color is not legal, and only throws illegal option errors back at me. So last week I set out to get some colors going. I have two options:

1) Find someone else's script who's already done this. Well, after 5 days of searching and finding hundreds of references to "ls --color" and nothing as far as someone else writing a script to provide color, this does not seem like an option.

2) Write my own script to do this. Since I mostly program in non-scripting languages, I thought "this can't be too difficult." Searching through man pages has led me to believe I can pipe the outputs of "ls -CF" into a script and then color each file based on what character it ends with. This poses some problems: what existing unix program can I use ( awk? ) to modify each word using regex, and what about non-standard file names that contain spaces?

This is my first scripting project that contains some meaningful depth, and otherwise being fairly new to scripting, I'm at a loss as to just how to do this. However, I do learn fast. Can anyone provide any tips/guidance as to how I can do this?
# 2  
Old 05-09-2005
Not sure if this is what you want, but you may want to look at BSD's ls. They use the -G flag for colorized output.

http://www.freebsd.org/cgi/man.cgi?q...ts&format=html
# 3  
Old 05-10-2005
Quote:
Originally Posted by jolok
Not sure if this is what you want, but you may want to look at BSD's ls. They use the -G flag for colorized output.

http://www.freebsd.org/cgi/man.cgi?q...ts&format=html

Nope, that doesn't help. The ls I have available for use has no coloring capability whatsoever. If it does, then it isn't specified anywhere in the man, nor has any switch I've tried to use done it for me.

Which is why I'm probably going to have to write something myself.
# 4  
Old 05-11-2005
*bump*

I take it noone has any ideas they'd like to share?
# 5  
Old 05-11-2005
Here's an idea: read the rules which say:

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.
# 6  
Old 05-12-2005
Not sure that there is any "meaningful depth" here...
Code:
ls -l | awk '
/^d/{printf "\033[34m%s\033[0m\n",$0;next}
/^l/{printf "\033[35m%s\033[0m\n",$0;next}
$1~"x"{printf "\033[36m%s\033[0m\n",$0;next}
{print}'

# 7  
Old 05-18-2005
Quote:
Originally Posted by Perderabo
Here's an idea: read the rules which say:

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.
Getting people to RTFM is hard enough, getting myself or anyone else to RTFR is next to impossible. However, thank you for quoting the rules.
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to change the background color in the init 3 mode(not line color)

Hello, I am using RHEL 6.1 on VMware I am searching for a way to change background color (not line by line color wich one can using tput command) basically changing the color of the whole screen to white instead of the default black and changing font color to black and alos would like to... (2 Replies)
Discussion started by: Dexobox
2 Replies
Login or Register to Ask a Question