Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ilnyckyj

macrumors member
Original poster
May 4, 2005
47
0
Okay, so i wanted my files/folders/filetypes to be displayed in different colors in the OSX terminal as it is done on other *nix systems. So i had a look at this link:

http://www.drunkenblog.com/drunkenblog-archives/000073.html

I got it done, and now i have colors. Only problem is that when something IS colored, it is also put into bold, or increased in size by a slight amount. I know it's not the biggest deal, but i'd like everything to match, but i can't figure out how to edit the colors. I'd also like to add some other filetypes for coloration, but can't figure out where to access the settings. I've even gone through the source for 'ls' and i still can't find it.

At the bottom of the page i linked to above, someone mentions in a comment that to do this you have to "edit your rc file to export the colors you want as environment variables." I think this refers to an older version of OSX, because i can't find what they're talking about. Anyone know how to do what i'm trying to do?
 
Did you check the new man pages? They usually state this sort of thing.
 
belvdr said:
Did you check the new man pages? They usually state this sort of thing.

i did actually, that was one of the things that i tried. The only thing that it mentions is enabling and disabling the colors, not editing them. I'm positive that there is a way to do it, though. It is weird that the man wouldn't have the information.
 
Yeah, I agree. You may have to check the docs that came with the source. Usually README or INSTALL files exist and tell you this.
 
ilnyckyj said:
Okay, so i wanted my files/folders/filetypes to be displayed in different colors in the OSX terminal as it is done on other *nix systems. So i had a look at this link:

http://www.drunkenblog.com/drunkenblog-archives/000073.html

I got it done, and now i have colors. Only problem is that when something IS colored, it is also put into bold, or increased in size by a slight amount. I know it's not the biggest deal, but i'd like everything to match, but i can't figure out how to edit the colors. I'd also like to add some other filetypes for coloration, but can't figure out where to access the settings. I've even gone through the source for 'ls' and i still can't find it.

At the bottom of the page i linked to above, someone mentions in a comment that to do this you have to "edit your rc file to export the colors you want as environment variables." I think this refers to an older version of OSX, because i can't find what they're talking about. Anyone know how to do what i'm trying to do?

ummmm.... that is like the hardest way possible to add color to terminal. Anyway, for a better color look in terminal try the built in color function in ls.

in your .bash_profile add
Code:
alias ls='ls -G'

here is an example .bash_profile

Code:
cow@supercow cow $cat .bash_profile
export PATH=/usr/local/mysql/bin:$PATH
export PATH=~/scripts:$PATH
export PATH=/usr/local/bin/:$PATH
alias ls='ls -G'
PS1="\[\033[0;34m\]\u\[\033[0;30m\]@\[\033[0;31m\]\h \[\033[0;30m\]\W $"
 
I believe you compiled gnu ls. The native Mac OS X ls is BSD ls. They are slightly different.

In any case, for gnu ls, the color coding is controlled by an environment variable called LS_COLORS. fileutils should also come with a program called dircolors. If yes, do this from a console:

dircolors >> ~/.bash_profile (or .profile, if you prefer. Man bash to learn the differences between these 2 files.)

You will see 2 lines appended to you .bash_profile. The "LS_COLORS=" line contains the color codes for the various file types which are separated by colon. Each color code is defined by 2 numbers separated by semi-colon. The first number is the character attributes (e.g. 01 is bold), while the 2nd number is the color (e.g. 31 is red). So "*.tgz=01;31" will list all tgz files as bold red.

To do what you want, i.e. turn off bold, just make sure that the first number is 00 for each file type you want to change.
 
superbovine said:
ummmm.... that is like the hardest way possible to add color to terminal. Anyway, for a better color look in terminal try the built in color function in ls.

in your .bash_profile add
Code:
alias ls='ls -G'

here is an example .bash_profile

Code:
cow@supercow cow $cat .bash_profile
export PATH=/usr/local/mysql/bin:$PATH
export PATH=~/scripts:$PATH
export PATH=/usr/local/bin/:$PATH
alias ls='ls -G'
PS1="\[\033[0;34m\]\u\[\033[0;30m\]@\[\033[0;31m\]\h \[\033[0;30m\]\W $"


umm where is this .bash_profile found and is there anything i need to do to make it work
 
It's in your home directory. You can see it via Terminal if you do a:

ls -la .bash_profile

If one doesn't exist, you can create it manually with no harm.
 
TextWrangler has a special option for opening hidden files. Very handy if you want to edit .bash_profile and other "dot-files" without using vi, emacs, pico or whatever text editor you can use in Terminal... :)
 
superwoman said:
I believe you compiled gnu ls. The native Mac OS X ls is BSD ls. They are slightly different.

In any case, for gnu ls, the color coding is controlled by an environment variable called LS_COLORS. fileutils should also come with a program called dircolors. If yes, do this from a console:

dircolors >> ~/.bash_profile (or .profile, if you prefer. Man bash to learn the differences between these 2 files.)

You will see 2 lines appended to you .bash_profile. The "LS_COLORS=" line contains the color codes for the various file types which are separated by colon. Each color code is defined by 2 numbers separated by semi-colon. The first number is the character attributes (e.g. 01 is bold), while the 2nd number is the color (e.g. 31 is red). So "*.tgz=01;31" will list all tgz files as bold red.

To do what you want, i.e. turn off bold, just make sure that the first number is 00 for each file type you want to change.


this doesn't work though. "-bash: dircolors: command not found" remember, i recompiled the ls command from GNU, but i still have bash from OSX, BSD, which wouldn't have that command.
 
ilnyckyj said:
this doesn't work though. "-bash: dircolors: command not found" remember, i recompiled the ls command from GNU, but i still have bash from OSX, BSD, which wouldn't have that command.

if you still have the OS X ls command then my post will work.

you need to edit your .bash_profile, just use ls -G all the time...

The point is you don't have to recompile anything or download anything color comes with ls out of the box.
 
superbovine said:
if you still have the OS X ls command then my post will work.

you need to edit your .bash_profile, just use ls -G all the time...

The point is you don't have to recompile anything or download anything color comes with ls out of the box.

Yes, but the problem isn't getting the color to work. I have color working fine, i'd just like to know how to edit the actual colors that are displayed for different file types and folders, and also how to add file types and assign colors to them.
 
ilnyckyj said:
Yes, but the problem isn't getting the color to work. I have color working fine, i'd just like to know how to edit the actual colors that are displayed for different file types and folders, and also how to add file types and assign colors to them.

http://www.macosxhints.com/article.php?story=20031027145026892

oh my bad... in your .bash_profile as well.

For more detail info you need to 'man ls' then /CLI your'll find all the info on tweaking the colors.

Code:
export CLICOLOR=1
# use yellow for directories
export LSCOLORS=dxfxcxdxbxegedabagacad
 
dircolors is not a bash command, it's another program. Since you don'y have it, then append these 2 lines into your .bash_profile (or .profile) and reopen a new terminal.

LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:eek:r=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:';
export LS_COLORS
 
superwoman said:
dircolors is not a bash command, it's another program. Since you don'y have it, then append these 2 lines into your .bash_profile (or .profile) and reopen a new terminal.

LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:eek:r=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:';
export LS_COLORS

EDIT: THIS ASSUME YOU DIDN'T HAVE THE ORIGINAL 'ls' from OS X oooops (i'll eat crow now....a lot of it)

ilnyckyj: it think it be easier to get the darwin source code for ls and recompile it back to the way it was a copy ls from a backup. (YUMMM CROW)



are you sure that is for os x? I believe that syntax comes dircolors from the linux end of things.

This is from the man for ls file

Code:
ENVIRONMENT

 LSCOLORS        The value of this variable describes what color to use
                     for which attribute when colors are enabled with
                     CLICOLOR.  This string is a concatenation of pairs of the
                     format fb, where f is the foreground color and b is the
                     background color.

                     The color designators are as follows:

                           a     black
                           b     red
                           c     green
                           d     brown
                           e     blue
                           f     magenta
                           g     cyan
                           h     light grey
                           A     bold black, usually shows up as dark grey
                           B     bold red
                           C     bold green
                           D     bold brown, usually shows up as yellow
                           E     bold blue
                           F     bold magenta
                           G     bold cyan
                           H     bold light grey; looks like bright white
                           x     default foreground or background

                     Note that the above are standard ANSI colors.  The actual
                     display may differ depending on the color capabilities of
                     the terminal in use.

                    The order of the attributes are as follows:

                           1.   directory
                           2.   symbolic link
                           3.   socket
                           4.   pipe
                           5.   executable
                           6.   block special
                           7.   character special
                           8.   executable with setuid bit set
                           9.   executable with setgid bit set
                           10.  directory writable to others, with sticky bit
                           11.  directory writable to others, without sticky
                                bit

                     The default is "exfxcxdxbxegedabagacad", i.e. blue fore-
                     ground and default background for regular directories,
                     black foreground and red background for setuid executa-
                     bles, etc.


dircolors on CentOS

Code:
# Configuration file for dircolors, a utility to help you set the
# LS_COLORS environment variable used by GNU ls with the --color option.

# The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
# slackware version of dircolors) are recognized but ignored.

# Below, there should be one TERM entry for each termtype that is colorizable
TERM linux
TERM linux-c
TERM mach-color
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM dtterm
TERM xterm
TERM xterm-color
TERM xterm-debian
TERM rxvt
TERM screen
TERM screen-w
TERM vt100
TERM Eterm

# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00       # global default, although everything should be something.
FILE 00         # normal file
DIR 01;34       # directory
LINK 01;36      # symbolic link.  (If you set this to 'target' instead of a
                # numerical value, the color is as for the file pointed to.)
FIFO 40;33      # pipe
SOCK 01;35      # socket
DOOR 01;35      # door
BLK 40;33;01    # block device driver
CHR 40;33;01    # character device driver
ORPHAN 40;31;01 # symlink to nonexistent file

# This is for files with execute permission:
EXEC 01;32

# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')

# If you use DOS-style suffixes, you may want to uncomment the following:
#.cmd 01;32 # executables (bright green)
#.exe 01;32
#.com 01;32
#.btm 01;32
#.bat 01;32

.tar 01;31 # archives or compressed (bright red)
.tgz 01;31
.arj 01;31
.taz 01;31
.lzh 01;31
.zip 01;31
.z   01;31
.Z   01;31
.gz  01;31
.bz2 01;31
.deb 01;31
.rpm 01;31
.jar 01;31

# image formats
.jpg 01;35
.jpeg 01;35
.gif 01;35
.bmp 01;35
.pbm 01;35
.pgm 01;35
.ppm 01;35
.tga 01;35
.xbm 01;35
.xpm 01;35
.tif 01;35
.tiff 01;35
.png 01;35
.mov 01;35
.mpg 01;35
.mpeg 01;35
.avi 01;35
.fli 01;35
.gl 01;35
.dl 01;35
.xcf 01;35
.xwd 01;35

# audio formats
.ogg 01;35
.mp3 01;35
.wav 01;35
 
okay, so anyone know where i can get the darwin source for ls? because now i have the other, and it would be way easier the other way.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.