免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: cwmould
打印 上一主题 下一主题

关于ls命令颜色问题! [复制链接]

论坛徽章:
0
1 [报告]
发表于 2004-07-24 00:40 |显示全部楼层

关于ls命令颜色问题!

去 sunfreeware.com 下载  coreutils-4.5.4-sol9-sparc-local.gz

论坛徽章:
0
2 [报告]
发表于 2004-07-24 04:31 |显示全部楼层

关于ls命令颜色问题!

寒江兄可真是多面手。 其实我是不用这些东西的, 只是回答问题而已。
很多从 Windows 及 Linux 转过来的人,动不动就要 GUI. 比如这位
就要 color.   UNIX 的纯洁度越来越差了。

索性好人做到底。

Coloured ls output in 10 steps

Always dreamt of having the same sort of output on your Solaris machine as you would have on Linux? Here is how you go at that.

   1. Coloured output is a feature of the GNU version of ls. So you first have to obtain this version. GNU ls is in the coreutils package. You can download it from (a mirror) of sunfreeware.com.

   2. Install the package using the pkgadd command:

root@host /var/tmp>; pkgadd -d coreutils-4.5.4-sol9-sparc-local

The following packages are available:
  1  SMCcoreu     coreutils
                  (sparc) 4.5.4

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: y
--output ommitted--

   3. This will install GNU ls and some other useful GNU programs in /usr/local/bin. Check this directory.

   4.  Information about the commands can be found in /usr/local/doc and /usr/local/man. Read the documentation for the new commands, e.g. for dircolors:

user@host ~>; man -M /usr/local/man dircolors

      Lateron, make sure that the MANPATH variable includes /usr/local/man.

   5. Colours can also be set system wide, in that case you need a DIR_COLORS file in /etc. It may look somewhat like this:

user@host ~>; cat /etc/DIR_COLORS
# Configuration file for the color ls utility
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.

# COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
COLOR tty

# Extra command line options for ls go here.
# Basically these ones are:
#  -F = show '/' for dirs, '*' for executables, etc.
#  -T 0 = don't trust tab spacing when formatting ls output.
OPTIONS -F -T 0

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

# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1

# 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
FIFO 40;33        # pipe
SOCK 01;35        # socket
BLK 40;33;01        # block device driver
CHR 40;33;01         # character device driver
ORPHAN 01;05;37;41  # orphaned syminks
MISSING 01;05;37;41 # ... and the files they point to

# 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 '#')
.cmd 01;32 # executables (bright green)
.exe 01;32
.com 01;32
.btm 01;32
.bat 01;32
.sh  01;32
.csh 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
.bz  01;31
.tz  01;31
.rpm 01;31
.cpio 01;31
.jpg 01;35 # image formats
.gif 01;35
.bmp 01;35
.xbm 01;35
.xpm 01;35
.png 01;35
.tif 01;35

   6. Test that your new setup works, using the /usr/local/bin/ls --color command in a couple of directories.

      If your colours seem ok (look also at other than plain text files), proceed to the next step.

   7. Now we don't want to type /usr/local/bin/ls --color all the time. You can solve the problem by altering your PATH variable:

user@host ~>; export PATH=/usr/local/binPATH

      This way, when you just type ls, the first occurance in your search path will be the ls from /usr/local/bin instead of the default one from /usr/bin.

   8. Now we already have the correct program when we call it, but we are lazier than that, because we don't want to type the --color option all the time either. So you might want to alias the ls command:

user@host ~>; alias ls='ls --color'

      Mind that this does not work for the common shell, /sbin/sh. You need a more advanced shell for making aliases, such as bash or ksh.

   9. Of course, when you log out, all these settings are gone, so add these lines to your shell configuration file, e.g. ~/.bashrc:

user@host ~>; echo 'export PATH=/usr/local/binPATH' >;>; ~/.bashrc
user@host ~>; echo "alias ls='ls --color'" >;>; ~/.bashrc

  10. In order to make these settings available for all users on the system, put these last two lines in /etc/profile (check first, if PATH is already defined, it is cleaner to arrange the existing definition.

论坛徽章:
0
3 [报告]
发表于 2004-07-26 22:49 |显示全部楼层

关于ls命令颜色问题!

大家各抒己见,令人耳目一新。 去过一些坛子,发觉这里的风气特别好。

对于前面我的话可能引起的误解,我表示歉意。

Linux 的贡献很大。 主要原因不在 Linux, 而是 GNU,  越来越多的主流
Unix 厂家将 GNU 版本的程序容纳其中. 但由于版权问题, 还不能正式采用.

论坛徽章:
0
4 [报告]
发表于 2004-07-26 23:11 |显示全部楼层

关于ls命令颜色问题!

知我者寒江兄也,   那就先行谢过了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP