Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Return color labeling to the ls command UNIX
The new ls command does not use the same old --color=auto argument. If you want to set up the color labeling again, put the following in your ~/.tcshrc file (if you are using tcsh as your default shell):

setenv TERM "xterm-color"
setenv CLICOLOR "true"
setenv LSCOLORS "exfxcxdxbxegedabagacad"
The TERM variable can be set in the Terminal Preferences also, but it won't turn on the color labeling until you add at least the CLICOLOR variable to your .tcshrc file.

Read the rest of the hint for more on color definitions.

The colors can be set with the LSCOLORS variable. 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 in the LSCOLORS variable is 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
They are set in pairs, foreground (f) then background (b), i.e. fbfbfbfbfbfbfbfbfbfbfb for all 11 settings. The default is exfxcxdxbxegedabagacad, i.e. blue foreground and default background for regular directories, black foreground and red background for setuid executables, etc.
    •    
  • Currently 3.00 / 5
  You rated: 3 / 5 (9 votes cast)
 
[50,429 views]  

10.3: Return color labeling to the ls command | 18 comments | Create New Account
Click here to return to the '10.3: Return color labeling to the ls command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
What about bash?
Authored by: d00d on Oct 30, '03 12:36:08AM

I don't really feel like changing my shell from the Panther default (bash). How can one accomplish this with bash?



[ Reply to This | # ]
What about bash?
Authored by: johnl on Oct 30, '03 12:45:51AM
You can add this to your .bashrc file in your home directory:

export TERM=xterm-color
export CLICOLOR=true
export LSCOLORS=exfxcxdxbxegedabagacad
According to the ls man page, the -G option accomplishes pretty much the same thing.

[ Reply to This | # ]
What about bash?
Authored by: adriaant on Oct 30, '03 12:53:22AM

Sigh, it's about time submitted osxhints are better edited. Rob, you need to hire people, I guess.

Anyway, this hint is so stale and is more a Jaguar tip and should have been updated so that it works in bash, which is the default shell. In bash and while using Terminal.app, all you need is edit (create if there isn't one) a .bash_profile file in your home dir (text file of course, and use vi or bbedit for it, not rich text editors) and add:

LS_COLORS='no=00;32:fi=00:di=00;34:ln=01;36:pi=04;33:so=01;35:bd=33;04:cd=33;04: or=31;01:ex=00;32:*.rtf=00;33:*.txt=00;33:*.html=00;33:*.doc=00;33:*.pdf=00;33: *.ps=00;33:*.sit=00;31:*.hqx=00;31:*.bin=00;31:*.tar=00;31:*.tgz=00;31:*.arj=00;31: *.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.deb=00;31: *.dmg=00;36:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.ppm=00;35:*.tga=00;35: *.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.mpg=00;37:*.avi=00;37:*.gl=00;37:*.dl=00;37: *.mov=00;37:*.mp3=00;35:'
export LS_COLORS;

Of course, the LS_COLORS definition is mine, and YMMV. Use dircolors to change values (see man dircolors).

[robg adds: For better readability, I have wrapped the LS_COLORS command above by inserting a line break -- remove the line breaks and enter it as one long line with no additional spaces.]

[ Reply to This | # ]
What about bash?
Authored by: fniessen on Oct 30, '03 03:24:33AM
Shouldn't this be
LSCOLORS=...
instead of
LS_COLORS=...
in the bash?
BTW I prefer to set enviroment variables in the .bash_profile file.

[ Reply to This | # ]
What about bash?
Authored by: vondrix on Oct 30, '03 06:31:23AM

There is no man dircolors. I think you are using GNU ls installed by fink, instead of the standard ls.



[ Reply to This | # ]
What about bash?
Authored by: robg on Oct 31, '03 08:08:12AM

[sarcasm]
Right, and I'll hire all those folks with the boatloads of money I'm making off the site.
[/sarcasm]

Sorry, for now it's up to the community of commenters. I test the hints, edit the hints, and put them online. This one worked and seemed interesting, so up it went.

Speaking of editing, I have edited your comment to break that really really long line into several lines -- makes for easier reading when people browse the site.

-rob.



[ Reply to This | # ]
What about bash?
Authored by: ghoppe on Nov 12, '03 05:55:39PM
Pretty arrogant of you to admonish Rob for not editing hints, and then submit a hint that will not work in either Jaguar or Panther out-of-the-box installs. This hint will only work if you have installed GNU file utilities (fileutils). You can do that through fink if you wish. (see Fink fileutils page.)

[ Reply to This | # ]
What about bash?
Authored by: elkef on Apr 08, '05 08:15:50AM

Hello,
Pretty new here, but if it helps,

just put this in ~/.bash_profile

export PATH=/usr/local/mysql/bin:$PATH
export CLICOLOR=1
export LSCOLORS=fxfxcxdxbxegedabagacad

And it will work.



[ Reply to This | # ]
10.3: Return color labeling to the ls command
Authored by: deleted_user18 on Oct 30, '03 01:21:02AM

This is great!

How can I make it work with "ll" with is a alias of ls Apple made for the tcsh.



[ Reply to This | # ]
10.3: Return color labeling to the ls command
Authored by: iu-macboy on Oct 30, '03 08:21:48AM
for the tcsh shell, issue this command...

alias ll 'ls -alG'

Then type ll. Presto! You can do the same for the ls too...

alias ls 'ls -G'

To do this in bash, use...

alias ll='ls -alG' and alias ls='ls -alG', respectively.

---



[ Reply to This | # ]

Correction...
Authored by: iu-macboy on Oct 30, '03 09:47:18AM
the last line should be...

alias ll='ls -alG' and alias ls='ls -G'

---



[ Reply to This | # ]

10.3: Using ~/.tcshrc file to make Permanent Aliased Commands
Authored by: SuperGenius on Oct 30, '03 10:08:17AM
You can make this addition once; you never have to issue another command.

To make ll always do what you want, place the following entry in your ~/.tcshrc file. (Create the ~/.tcshrc file if it doesn't already exist. That's a file called .tcshrc in your home directory). Add the following line to this file :

alias ll 'ls -l'
You can also add any other flags after the " -l " to customize your file-listing experience. See the man page for ls (type " man ls ") to see all the options that you can use to customize the ls command.

[ Reply to This | # ]
PROBLEM with more
Authored by: zeorge on Oct 30, '03 07:26:35AM
hi ! cool i dont have to install fink fileutils anymore ! but ....
if i use more in a pipe after ls like 'ls -la | more'
the colors get lost somehow. (panther)
any solution for this?
zeo

[ Reply to This | # ]
PROBLEM with more * solution
Authored by: zeorge on Oct 30, '03 11:23:52AM

setenv CLICOLOR "true"
setenv CLICOLOR_FORCE "true"
alias l "ls -Flk \!* | more -r"
alias ll "ls -Flak \!* | more -r"

this is only what it needs for tcsh...
infos in man pages of ls and more



[ Reply to This | # ]
This hint is wayyyyyyyyyy too complicated
Authored by: rae on Oct 30, '03 01:57:18PM
Here are much simpler instructions:

in csh/tcsh: setenv TERM dtterm
in bash/sh/ksh/zsh: export TERM=dtterm

I prefer dtterm to xterm-color. It doesn't really matter too much.

Now just use the "-G" flag. That's it! None of that other stuff is required:

% ls -G

Wow, eh?

[ Reply to This | # ]

10.3: Return color labeling to the ls command
Authored by: EatingPie on Oct 31, '03 05:55:15PM

You don't need "xterm-color" as your default. I have used vt100 since Jaguar because I like its idiosycracies (sp?) much more than xterm's. You change your Terminal Preferences to select vt100, and on OS X, vt100 is color compatible.

tcsh

setenv TERM vt100
bash

export TERM=vt100
For gnu ls, you need to tell it that vt100 does support color. In your ".dircolorsrc" file, add the following line if it ain't there:

TERM vt100

That will allow gnu ls to work with vt100. Apple's (BSD's) ls works out-of-box with vt100.

---
-Pie


[ Reply to This | # ]

For testing/customization purposes..
Authored by: cynikal on Jan 20, '04 03:25:30PM

In case you want to see what everything looks like, you can try these set of commands to create one of each (10 and 11 are in hexadecimal 'a' and 'b' for ls sorting purposes):

mkdir test
cd test
mkdir 1 a b
touch 0 5 8 9
ln -s /dev/null 2
ln /tmp/slp_ipc 3
mkfifo 4
sudo mknod 6 b 14 0
sudo mknod 7 c 3 2
chmod 777 5 8 9 a b
chmod +t a
chmod u+s 8
chmod g+s 9
ls -l



[ Reply to This | # ]
For testing/customization purposes..
Authored by: morgion on Dec 22, '04 09:49:28AM

Thanks cynikal!

A few customizations I made:
1. More descriptive names; dual benefits of longer text and reminding you what you're looking at.
2. Added a simple 'sudo' command (prints a heading) at the beginning to get authentication out of the way.

Just copy/paste the whole block, and if you have to authenticate, paste it again after entering your password; there won't be any lingering files or directories from a partial run.

sudo echo "## create dir 'color_test' for colorization preview ##"
mkdir color_test
cd color_test
mkdir 1-directory a-dir_writeothers_sticky b-dir_writeothers_NOsticky
touch 0-file 5-executable 8-exe_setuid 9-exe_setgid
ln -s /dev/null 2-sym_link
ln /tmp/slp_ipc 3-socket
mkfifo 4-pipe
sudo mknod 6-block_special b-dir_writeothers_NOsticky 14 0
sudo mknod 7-char_special c 3 2
chmod 777 5-executable 8-exe_setuid 9-exe_setgid a-dir_writeothers_sticky b-dir_writeothers_NOsticky
chmod +t a-dir_writeothers_sticky
chmod u+s 8-exe_setuid
chmod g+s 9-exe_setgid
ls -la



[ Reply to This | # ]