








			   Linux ն˻µĲɫʾ

		 : Thorbjrn Ravn Andersen, ravn@dit.ou.dk

		       : Chou-Kai Wang, stylon@ms2.hinet.net

			      v1.4, 7 August 1997



				   Abstract

     Ȼ󲿷ݵ Linux
     а汾һĿ¼гҿòɫǿӾϵЧ
     'ls'ָҪ趨ĺȴǼ׵¡
     ļ˵趨һЩѾڸ Linux
     а汾壬ﵽĿصĺüֲͬķ
     ǡҵһЩڴ󲿷ݰ汾 Unix
     õȴ Slackware  RedHat Linux 塣
     ļ HTML 汾Ҳҵԭʼ
     <URL:http://www.mip.ou.dk/~ravn/colour-ls> ҵĵ



1.  

ЩɫʾѾ൱ձ飬ʹҲʼʹһЩԲɫʾ磺ʽԡı֣ƴ֣ʹһЩӾϵĻ

Դ Linux ģʽ̨֧Ԯɫᣬԭ GNU ls
Ҳܿı޸ĳ֧ԮɫѶϢұ Slackware 2.0 
Щԭ汾׺Ѿϵ׼ GNU ls ҲӦµ
Linux а汾һˡ

汾ļǰİ汾дಿ¶ģһЩ xterm
 ׺ºĵѶ

ļѶ Redhat 4.1 ֤ҪSlackware 2.0.2
漰İ汾 1.1.54 ĻѼġ ĵ׺Ѷ slackware
2.2.01.2.13 ĺģ tcsh ΪԤ shellĻȡõģ Ҳ
2.0.27 ĺġ֤ʹ趨 unix
汾һܸмҵϵͳ汾 Ƿ֧Ԯɫʾ


2.  ţûĵĶ

и °
LinuxʹĿ¼µЩЩ޸ģ´ʱͻЧˡ







Linux ն˻µĲɫʾ						      1





Linux ն˻µĲɫʾ						      2



     ~/.bashrc:
	 alias ls="ls --color"

     ~/.cshrc:
	 alias ls 'ls --color'



ͺ

ҲҪ``eval `dircolors $HOME/.colourrc`''
趨ԼҪɫ ``dircolors -p >$HOME/.colourrc''
ҡעⷽ趨


3.  ͺ?

Ҫ֪ʹõ ls ǲǿʵĴɫ Linux
ģʽ̨Կָ( xterm Ҳ):

     % ls --color

( %  shell ʾ):

㿴˱ʾ ls ܽѡĴѶϢӦðװ°汾 GNU
fileutils 塣ʹõķа汾ûṩµ壬ʹ GNU
ӳվ̨ȡ岢ֱӴԭʼ밲װ

㲢ûпѶϢʹõ ls
ԽѡܲҵģһЩ Slackware (ķа汾Ҳп)
ڰ汾гġ Redhat 4.1 渽 3.13  ls û⡣

     % ls --version
     ls - GNU fileutils-3.13

 Linux ģʽն˻ִ ``ls --
color''ӦϵͳԤֵʵĲɫڿԿʼǲҪıκε趨

 xterm ִḶ́Ҳ㻹û취ɲɫ͸ ls
һԭ xterm ֧ԮӦóʽĲɫµİ汾֧Ԯ
xterm ֧ԮɫοļĽβõ°汾
xtermͬʱҲֻлģʽҼĲ衣


4.  Щɫѡ?

 shell (л bash
İ汾ĸҵ)ʾʹǫܹ֧̃Ԯĸɫϡûɫ̨֣Ͳ֧Ԯ
ANSI ɫѡ













Linux ն˻µĲɫʾ						      3



     #!/bin/bash
     # ʾ ANSI Ĳɫ
     #
     esc="\033["
     echo -n " _ _ _ _ _40 _ _ _ 41_ _ _ _42 _ _ _ 43"
     echo "_ _ _ 44_ _ _ _45 _ _ _ 46_ _ _ _47 _"
     for fore in 30 31 32 33 34 35 36 37; do
       line1="$fore  "
       line2="	  "
       for back in 40 41 42 43 44 45 46 47; do
	 line1="${line1}${esc}${back};${fore}m Normal  ${esc}0m"
	 line2="${line2}${esc}${back};${fore};1m Bold	 ${esc}0m"
       done
       echo -e "$line1\n$line2"
     done

ǰɫһţϷҪԪ͸Ⱦڲһ
"1"ǰǰɫɫͳ "37;44;1" ANSI ɫѡо

     ESC [ 3 7 ; 4 4 ; 1 m

 

ע:
ǸȣԻɫ(ȵɫ)ֻǰӲϵơ

     ɫ:
	     0 - ɫ	  4 - ɫ	     3# Ǳɫ
	  1 - ɫ     5 - ۺɫ	  4# ǰɫ
	  2 - ɫ     6 - ɫ
	  3 - ɫ     7 - ɫ 	  ;1 Ǵ͸


5.  趨 ls Ĳɫ

Ҫ޸ ls ڶı׼ɫҪָ HOME
Ŀ¼һ

      cd ; dircolors -p > .coloursrc

༭עĺϸĵᣬҪĻ LS_COLORS
ͨ

     eval `dircolors .colourrc`


ȻҪǰһзŽ .bashrc  .cshrc  .tcshrc (ʹõ shell
)ϸ÷뿴 dircolors(1) ʹ˵


6.  θıϵͳԤֵ: ǰɫǺɫ

Ҫն˻ʽҪһԤֵҪûһ׼ķ
Linux Ļ setterm ʽá








Linux ն˻µĲɫʾ						      4



"setterm" ʹն˻Ͽ趨ԡҪѡԵĻҪ

     setterm -foreground black -background white -store

"-store" ĸı趨ԤֵҪʹõĵն˻(
TERM ) termcap Ͽ㹻ϸļ¼ setterm
ΪĳزĹ㻹ѡ

6.1  Xterm

Ҫһе xtermҪ֧Ԯɫ

     xterm -fg white -bg blue4
     color_xterm -fg white -bg blue4
     color-xterm -fg white -bg blue4
     nxterm -fg white -bg blue4

 'color_xterm' ֧Ԯɫ 'ls'ɫѡģ SGI
ʹõɫ

6.2  ̨

Ҳ޸ĺģͿһݵÿı̨ԤֵԼĵĻҽ
kernel ׺

ĵԭʼ /usr/src/linux/drivers/char/console.c  1940
УӦ޸ĵĵط

	  def_color	  = 0x07;   /* white */
	  ulcolor	 = 0x0f;   /* bold white */
	  halfcolor	  = 0x08;   /* grey */



	  def_color	  = 0x17;   /* white */
	  ulcolor	 = 0x1f;   /* bold white */
	  halfcolor	  = 0x18;   /* grey */

ߵʮλǸʾõ: ߵλԪ( "1")Ǳ ;
ұߵλԪǰ0 = ɫ1 = ɫ2 = ɫ3 = ɫ,  4 = ɫ, 5 =
ɫ6 = ɫ/ɫ7 = ɫּ 8
Եõȵɫڴ󲿷ݵ£ȵıɫ ==
˸ּͨı  sjlam1@mda023.cc.monash.edu.au1  ṩ

Ҳʹ ANSI
ṩһִʱڵ̨Ԥֵ(ںԭʼҵ)

	  ESC [ 8 ]

ԤֵĿǰǰɫȻԵĿ(ESC [
m)ԤֵϾȡڰɫΪʹеɫ

____________________

1. <URL:mailto:sjlam1@mda023.cc.monash.edu.au>







Linux ն˻µĲɫʾ						      5



ÿؿʱ㶼ҪٰЩִ͸̨ Linux
;ͬкüԴĿġ

6.2.1  /etc/issue

 Slackware  "Welcome to Linux xx.yy"
ѶϢڵĵǸʹõĻǲѡ(
telnet Զ˵ʹϵͳ˾Ϳе)
ÿοʱᱻԭ򱻸ǣҪ޸Ŀ(
Slackware  /etc/rc.d/rc.SRedhat /etc/rc.d/rc.local)м:

       echo ""> /etc/issue
       echo Welcome to Linux `/bin/uname -a | /bin/cut -d\  -f3`. >> /etc/issue


ĳ

       ESCAPE=" ESC "
       echo "${ESCAPE}[H${ESCAPE}[37;44m${ESCAPE}[8]${ESCAPE}[2J"> /etc/issue
       echo Welcome to Linux `/bin/uname -a | /bin/cut -d\  -f3`. >> /etc/issue

Ŀαλ趨ɫ(ǰǰɫɫ)趨ҰөĻ
ĸı´ؿʱЧ emacs Ҫ ESC ԪҪ C-q 
vi Ҫ control-vΪȻִϳʽ sh ˽ /033 ÷

6.2.2  /etc/profile  .profile

       if [ "$TERM" = "console" ]; then
	   echo "\033[37;44m\033[8]" #
     # ʹ setterm
	   setterm -foreground white -background blue -store
       fi

6.2.3  /etc/login  .login

       if ( "$TERM" == "console" ) then
	 echo "\033[37;44m\033[8]"
     # ʹ setterm
	   setterm -foreground white -background blue -store
       endif

[ ע: Linux ̨µ $TERM Ѿ "linux"  "console"  ]

6.3  Զ˵

Ӧÿʾ setterm
ʽȻԶ˵ĻҪܹõ㹻Ѷն˻ն˻ģʽҪܹ֧Ԯɫ
ҵľƽ̨õ vt100 ն˻ģʽм:

    MS-DOS:	     MS-Kermit (,  Microsoft ĲƷ)

    Windows 95/NT:  Kermit/95 ()










Linux ն˻µĲɫʾ						      6



    OS/2:	     Kermit/95 () ע׼ telnet
     ֧Ԯɫҿڱض趨

 kermit ϸ뿴 <URL:http://www.columbia.edu/kermit/>


7.  

е÷ʹõ
GNU/Linuxʹҵ(˵ִ X  Sun
վȵ)㻹ǿõԼЩ塣

ɫ xterm Ǵӱ׼ xterm ԭʼչģ޸ı׼ xterm
׺Դκһ X11R6 վ̨á ˵ R6.3 ڸ xterm
֧ԮɫûвԹ

     ftp://ftp.denet.dk/pub/X11/contrib/utilities/color-xterm-R6pl5-patch.gz


þɰ X Ļ뿴ڸļע: ԼûвԹ!

'ls' ڸ GNU  fileutils Դ prep.mit.edu
ӳվ̨õµ 3.13 汾

     ftp://ftp.denet.dk/pub/gnu/fileutils-3.XX.tar.gz

Լ SolarisSunOSIrix ϳɹ color-ls

ҺܻӭƪµĻӦҵĵʼַ ravn@dit.ou.dk2

--

Thorbjrn Ravn Andersen



















____________________

2. <URL:mailto:ravn@dit.ou.dk>







Linux ն˻µĲɫʾ						      7





































































				   CONTENTS



1.  ..................................................................... 1

2. ţûĵĶ ......................................... 1

3. ͺ? ............................................................ 2

4. Щɫѡ? .................................................... 2

5. 趨 ls Ĳɫ ................................................... 3

6. θıϵͳԤֵ: ǰɫǺɫ ............................... 3
   6.1 Xterm ................................................................ 4
   6.2 ̨ ........................................................... 4
   6.3 Զ˵ ............................................................. 5

7.  ..................................................................... 6




































				       i


