Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

When I do an ls of a directory and a shell script is listed as a directory item, is there a way I can have a visual indication that it is a shell script ?

For example:

From /opt/local/bin 
ls -l

Displays port from MacPorts as an ordinary item:

port

Can I have color coding, bold or some other way to see this ? I know I can use file to check if it's a script, executable, etc., but that's an extra command I have to issue and is no better than trying to run port and then getting an error and typing ./port.

Thanks!

Scott

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

Try typing ls -G in terminal, you should see colored listings by file type. If the scripts aren't being shown in a different color, this means that they are not marked as executable, so you will need to type sudo chmod +x <filename> to make them so. Then they should appear in a different color as opposed to directorys etc.

If you prefer not to always type ls -G then you can put the following command in your .bashrc file in your home directory alias "ls"="ls -G" Then restart terminal and you should see colored output whenever you just type ls

share|improve this answer
1  
I'm pretty sure there is an environment variable that controls ls's color options. That would be the better thing to change –  Fake Name May 25 '11 at 1:56
    
@Fake Name - Thanks guys! This is what I was looking for. –  Scott Davies May 25 '11 at 11:09
add comment

You can set this in your ~/.bash_profile file to enable colors equivalent to ls -G:

#!/bin/sh
export CLICOLOR=1
share|improve this answer
add comment

As I’m not a fan of colours — they depend on the current terminal colour settings to look good — I prefer to use ls -F.

Borrowing from SCO Unix, I define an lf alias in ~/.bashrc:

alias lf="ls -F"

Executable files such as shell scripts show up with a * at the end of their names. Similarly, / for directories and @ for symbolic links.

share|improve this answer
    
Thanks! The color highlighting was what I was looking for, but I had no idea of the asterisk option - I'll add this to my toolkit. –  Scott Davies May 25 '11 at 11:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.