免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 9383 | 回复: 28
打印 上一主题 下一主题

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

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-07-23 16:15 |只看该作者 |倒序浏览
solaris8 (sparc),为什么ls的没有颜色来区分文件与目录呢,而redhat 8就有,我把linux上的/etc/DIR_COLORS文件拷至SUN上也不行呀,为什么呢?

论坛徽章:
0
2 [报告]
发表于 2004-07-24 00:40 |只看该作者

关于ls命令颜色问题!

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

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-03 17:23:07综合交流区版块每日发帖之星
日期:2015-08-19 06:20:00综合交流区版块每日发帖之星
日期:2015-09-15 06:20:00
3 [报告]
发表于 2004-07-24 01:35 |只看该作者

关于ls命令颜色问题!

原来这个颜色也要安装的呀?!   又学到一招

论坛徽章:
0
4 [报告]
发表于 2004-07-24 04:04 |只看该作者

关于ls命令颜色问题!

以前这个包叫做fileutil,现在并到coreutil里面去了。光速真不错。加完包以后,还要在.bashrc 或.cshrc 加上alias ls=`/usr/local/bin/ls --color`

论坛徽章:
0
5 [报告]
发表于 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
6 [报告]
发表于 2004-07-26 13:25 |只看该作者

关于ls命令颜色问题!

楼上这位老兄,好像把solaris说的是自命清高似的,有颜色不是好事,难道位老兄余凭着名字就能区分文件及目录,好眼力!难道unix就得原始,如果老兄水平这么高,不如自己去写个内核好了,什么都不加载,用什么都利自己编,这样更加纯洁(这也是我的理想,可俺做不到,只是在努力罢了,莫非这位老兄已经达到这样的顶极hacker的水平?)

论坛徽章:
0
7 [报告]
发表于 2004-07-26 14:37 |只看该作者

关于ls命令颜色问题!

ls -al的输出就可以判断是目录还是文件

-rwxr-xr-x ... 文件
drwxr-xr-x ... 目录

论坛徽章:
0
8 [报告]
发表于 2004-07-26 14:54 |只看该作者

关于ls命令颜色问题!

ls -F 好像是这个参数显示的时候后面跟个符号,而且是宽行显示

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
9 [报告]
发表于 2004-07-26 16:49 |只看该作者

关于ls命令颜色问题!

[quote]原帖由 "cwmould"]楼上这位老兄,好像把solaris说的是自命清高似的,..........[/quote 发表:


我觉得lightspeed兄实际上表达了这么一层意思,UNIX和WINDOWS实际上是两个非常不同的领域,后者是面向大众化,前者是强调专业化。因此两者的操作、管理风格非常不同,不好妄比。大众化的东西当然要方便操作、引人耳目,专业化的东西需要知识的积累和细致的分析。因此象颜色包这样的东东,UNIX厂商不是不能做,而是它不把重点放在这方面(对SUN的机器,显卡显示示器都是外设选件)。UNIX下很多软件,配置时可以用图形界面,但一些危险的操作则不放在GUI中,一定要用复杂的命令行才可以实现。UNIX这种近乎笨拙的简朴,实际是对系统管理员水平的严格要求,一种安全上的防范。

论坛徽章:
0
10 [报告]
发表于 2004-07-26 17:51 |只看该作者

关于ls命令颜色问题!

我也理解这位老兄的大致意思,我至今使用solaris linux等5年左右了,公司的大部分应用都在这上面,而配置这些时我想没人会是从GUI上配置的(大部分估计都得自己编程),我现在看一些linux内核的书及自己在编制简单的linux 下C程序(初学者+爱好者),我也喜欢用键盘控制计算机的感觉,我觉得这是所有unix爱好者的爱好(当然比不上那些对着AS400等的高手),也是对windows用户的骄傲吧,但我绝不反对通过一些工具来改进自己的工作,这些指令我当然知道,但你想想,你是用ls -al还是用改进后的ls(靠颜色区分)方便,当你每天在使用N次的时候?而且它并不能完全达到这样的效果(区分文件与目录,区分可执行文件等,而且是看颜色的方便还是从一大行找方便?)以上只是小例子,我就是从linux与solaris的对比中感觉前者确实方便。
我的意思是说,不论是不是GUI,是不是专业者,只要是优点,我就得学,而不是守着所谓的专业(这说明你有了一定的惯性)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP