
正文
linux里ls命令颜色 linux变色
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
MacOS X终端为ls命令设置颜色输出
ls 命令是linux系统下运用的最多的命令之一,有时候我们希望 ls 能彩色化输出,以区分文件、目录或不同文件类型,让我们一眼就能辨识出不同的文件类型。在Apple MacOS X或FreeBSD操作系统,我们并不用安装其他设置,只需要在执行 ls 命令是指定 -G 参数即可开启默认彩色化输出。
先 man ls 看一下 -G 参数的说明:
就是说 ls 指定 -G 参数可以开启彩色化输出,相当于在环境变量中设置了 CLICOLOR 。我们可以把 -G 参数设置为 ls 命令的默认参数,将如下内容添加到 ~/.bash_profile 文件末尾处:
添加之后执行 source ~/.bash_profile ,再 ls 看看是不是已经彩色化输出了?
我们没有指定设定任何颜色,但在终端,我们已经能够看到彩色化的输出,这是因为当我们指定了 -G 参数后,环境变量中默认设置了 CLICOLOR ,并且 LSCOLORS 环境变量默认设置为了:
这是啥?继续往下看如何定制化彩色输出吧。
这个时候,我们任然需要依靠这个"男人(man)", man ls 。手册中说明环境变量 CLICOLOR 和 LSCOLORS 会影响到ls彩色化输出。我们可以设置环境变量 CLICOLOR 和 LSCOLORS 来定制化彩色输出,同样在 .bash_profile 文件末尾设置增加以下环境变量:
同样使之生效: source ~/.bash_profile 。
对于 LSCOLORS 环境变量,其格式为 fb 配对的11组字符串,其中 f 是前景颜色(foreground color), b 是背景颜色(background color),支持的颜色指定如下:
对于 LSCOLORS=exfxcxdxbxegedabagacad 每组含义如下:
所以,对于默认LSCOLORS的值: LSCOLORS=exfxcxdxbxegedabagacad 表示:蓝色前景,默认背景的目录;洋红前景,默认背景的链接文件;...
相关问答
Q1: linux系统ls -l命令查看一个文件的信息的时候,最后的文件名是绿色什么意思。。
绿色表示该文件是可执行文件。
首先解释一下,我使用了securecrt,终端显示选择linux方案。
下图中几个文件颜色的解析:
白色:普通文件,本身用户具备读写属性,其他用户只有读权限;
红色:RPM文件
绿色:表示可执行文件
蓝色:是目录文件
Q2: linux系统下如何显示关键字颜色
linux下设置ls命令显示文件、文件夹颜色:
1. LS_COLORS
用 dircolors -p 可以 看到缺省的颜色设置,包括各种颜色和“粗体”,下划线,闪烁等定义。
环境变量LS_COLORS时用来设置GNU ls的--color选项中的颜色的。
# 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
故,要设置ls的颜色,则在SHELL的配置文件(以下是tcsh的配置文件:.tcshrc,对于bash略有不同)中添加下面一行:
setenv LS_COLORS 'no=00:fi=00:di=01;33:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;35:*.cmd=01;35:*.exe=01;35:*.com=01;35:*.btm=01;35:*.bat=01;35:*.sh=01;35:*.csh=01;35:*.tar=01;31:*.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:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:'
即可,可以参照上面的英文自行配置。
另:/etc/DIR_COLORS 文件为系统默认颜色参数配置文件
如果想修改定义自己的颜色参数配置文件,请执行如下操作:
1) cp /etc/DIR_COLORS $HOME/.dir_colors
2) 修改中的颜色定义 $HOME/.dir_colors
2. CLICOLOR
# CLICOLOR是用来设置是否进行颜色的显示。CLI是Command Line Interface的缩写。
setenv CLICOLOR 1
# LSCOLORS是用来设置当CLICOLOR被启用后,各种文件类型的颜色
setenv LSCOLORS gxfxaxdxcxegedabagacad
LSCOLORS的值中每两个字母为一组,分别设置某个文件类型的文字颜色和背景颜色。LSCOLORS中一共11组颜色设置,按照先后顺序,分别对以下的文件类型进行设置:
directory
symbolic link
socket
pipe
executable
block special
character special
executable with setuid bit set
executable with setgid bit set
directory writable to others, with sticky bit
directory writable to others, without sticky bit
LSCOLORS中,字母代表的颜色如下:
a 黑色
b 红色
c 绿色
d 棕色
e 蓝色
f 洋红色
g 青色
h 浅灰色
A 黑色粗体
B 红色粗体
C 绿色粗体
D 棕色粗体
E 蓝色粗体
F 洋红色粗体
G 青色粗体
H 浅灰色粗体
x 系统默认颜色
所以,如果我们想把目录显示成红色,就可以把LSCOLORS设置为bxfxaxdxcxegedabagacad就可以了
////////////////////////////////////////////
LSCOLORS 的含义:
LSCOLORS The value of this variable describes what color to use
for which attribute when colors are enabled with
CLICOLOR. This string is a concatenation of pairs of the
format fb, where f is the foreground color and b is the
background color.
The color designators are as follows:
a black
b red
c green
d brown
e blue
f magenta
g cyan
h light grey
A bold black, usually shows up as dark grey
B bold red
C bold green
D bold brown, usually shows up as yellow
E bold blue
F bold magenta
G bold cyan
H bold light grey; looks like bright white
x default foreground or background
Note that the above are standard ANSI colors. The actual
display may differ depending on the color capabilities of
the terminal in use.
The order of the attributes are as follows:
1. directory
2. symbolic link
3. socket
4. pipe
5. executable
6. block special
7. character special
8. executable with setuid bit set
9. executable with setgid bit set
10. directory writable to others, with sticky bit
11. directory writable to others, without sticky
bit
The default is “exfxcxdxbxegedabagacad”, i.e. blue fore-
ground and default background for regular directories,
black foreground and red background for setuid executa-
bles, etc.
Q3: linux下ls -color显示的是什么颜色
ls命令用于列出指定目录下文文件。
-C|--color[=WHEN]参数的作用是让每栏由上至下列出项目,同时控制是否使用色彩分辨文件。WHEN 可以是"never"(默认)、"always"或"auto"其中之一。
文件不同的颜色表示文件不同的类型,下面是linux系统默认不同类型文件所使用的颜色:
白色:表示普通文件
蓝色:表示目录
绿色:表示可执行文件
红色:表示压缩文件
浅蓝色:链接文件
红色闪烁:表示链接的文件有问题
黄色:表示设备文件
灰色:表示其它文件
Q4: linux中ls-l命令显示出来的三种颜色代表什么文件
蓝色代表的是目录,
绿色代表的是可执行文件,
红色代表的是压缩文件,
浅蓝色代表链接文件,
灰色代表其他文件
linux里ls命令颜色的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于linux变色、linux里ls命令颜色的信息别忘了在本站进行查找喔。







