
                           Linux ն˻µĲɫʾ
                                       
: Thorbj&oslash;rn Ravn Andersen, ravn@dit.ou.dk
: Chou-Kai Wang, stylon@ms2.hinet.net

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

2. ţûĵĶ

3. ͺ?

4. Щɫѡ?

5. 趨 ls Ĳɫ

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

     * 6.1 Xterm
     * 6.2 ̨
     * 6.3 Զ˵
       
7. 
     _________________________________________________________________
   
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ʹĿ¼µЩЩ޸ģ´
   ʱͻЧˡ
   
~/.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 ɫѡ
   
#!/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 ʽá
   
   "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 Եõȵɫ
   󲿷ݵ£ȵıɫ == ˸ּͨı 
   [2]sjlam1@mda023.cc.monash.edu.au ṩ
   
   Ҳʹ ANSI ṩһִʱڵ̨Ԥֵ(ںԭ
   ʼҵ)
   
        ESC [ 8 ]

   ԤֵĿǰǰɫȻԵĿ(ESC [
   m)ԤֵϾȡڰɫΪʹеɫ
   
   ÿؿʱ㶼ҪٰЩִ͸̨ Linux 
   ;ͬкüԴĿġ
   
  /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 ÷
   
  /etc/profile  .profile
  
  if [ "$TERM" = "console" ]; then
      echo "\033[37;44m\033[8]" #
# ʹ setterm
      setterm -foreground white -background blue -store
  fi

  /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 ()
     * OS/2: Kermit/95 () ע׼ telnet ֧Ԯɫҿ
       ض趨
       
    kermit ϸ뿴 [3]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
   
   ҺܻӭƪµĻӦҵĵʼַ [4]ravn@dit.ou.dk
   
   --
   
   Thorbj&oslash;rn Ravn Andersen

References

   1. http://www.mip.ou.dk/~ravn/colour-ls
   2. mailto:sjlam1@mda023.cc.monash.edu.au
   3. http://www.columbia.edu/kermit/
   4. mailto:ravn@dit.ou.dk
