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

Colorized 'ls' in the Terminal UNIX
I was talking to someone over on MacSlash and they commented that their 'ls' command didn't output in color. Hmmph...mine did. I looked and found that I had some "carry-overs" in my .cshrc file from my SGI box. To give yourself colorized 'ls' add the following lines to the end of your .cshrc (if you are using tcsh as your default shell):
  alias ls 'ls-F'
setenv LS_COLORS 'di=35:fi=0:ex=31:or=90'
set color
You can change the colors and/or styles for different types of files by using the variables on the second line. Linux StepbyStep provides a good reference guide on color setting.

Hope everyone enjoys their color!
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)

Colorized 'ls' in the Terminal | 6 comments | Create New Account
Click here to return to the 'Colorized 'ls' in the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
adds problems with 'l'
Authored by: felixv on Nov 22, '01 01:14:57PM
the above tip adds pretty colours, but when i try to use the command 'l' (to list contents with permissions) i get:
ls: -lg: No such file or directory
or have i screwed something up?

[ Reply to This | # ]
adds problems with 'l'
Authored by: mdr612 on Nov 22, '01 04:31:57PM

Actually, it disables all 'ls' modifiers, as well as 'l' and 'll'.

[ Reply to This | # ]
adds problems with 'l'
Authored by: cj69collins on Nov 22, '01 08:26:34PM
if you enter the command 'alias' plain, you should see something similar to this:
alias l '/bin/ls -lg' alias ll '/bin/ls -lag \!* | more'
Works like a scream. :-O ps: you must escape the bang, or the alias will lose its green card. [The form may be too stupid to place them

[ Reply to This | # ]
use color ls
Authored by: jimr on Nov 22, '01 08:54:08PM

ls-F command is built into the shell.

get file utilities 4.x from source forge and either build ls which supports color or search this site for more details and a possible link to a binary file.

[ Reply to This | # ]
Something's fishy...
Authored by: ebow on Nov 24, '01 09:53:47PM
Okay, I thought I had this mostly figured out, but I guess not... Why does "ls-F" give me a different result from "ls -F" (note the space in the second example)? When I type "ls-F" (no space) I now get color output, but when I type "ls -F" I get the same formatting with no color. The flag -F is just something to get / to appear after folders, and * to appear after "executables" (kinda). Could the reason be buried in the slew of aliases that have been definded between /usr/share/init/tcsh/aliases and ~/Library/init/tcsh/aliases.mine ? The first defines: alias l 'ls -lg' alias ll 'ls -lag !* | more' while the second defines: alias lsm 'ls -F -l!*|more' alias ls 'ls -F' alias l 'ls -F -l ' I know I've redefined "l" in the second, but it doesn't affect this situation. Besides, the 'g' flag does nothing anyway. Anyway, any help on figuring this all out? While using tcsh? What about "ls --color"? That doesn't do anything for me, not even report an error. Is it a bash flag? I don't feel like getting into bash...

[ Reply to This | # ]
Notes on ls-F and ls -F
Authored by: ali on Nov 27, '01 10:13:32AM

You get different results because you actually use different commands.

ls -F calls the ls command (usually in /bin) with the Flag -F so you get the listing with symbols like / (for dir) or @ (for sym link) after every file. See man ls.

ls-F (no space) calls the bultin function of tcsh or bash - not the ls command of /bin. This builtin can't take any additional options in your command line. Alas you can set a tcsh variable called listflags to alter the behavior of ls-F. If you set the variable to a (set listflags = a) ls-F will produce a colored output equivialent to ls -a (note space). See man tcsh.

the --color option does not work as ls is not compiled with this option (afaik). You would need to get the sources and recompile it.

Hope it helps,


[ Reply to This | # ]