打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
archlinux改变终端文字的颜色,提高效率。。
archlinux改变终端文字的颜色,提高效率。。
sjwkwang_发布于 2011-5-04

默认情况下,archlinux的终端显示的是黑白的。。比如root@arch:~# 都是黑白的,偶尔在往回看时,不容易很快找到root@arch:~#。。root下ls出来的也是黑白的,不能直观的分辨出哪个是文件夹哪个是文件。。浪费时间。。而在gentoo下花花绿绿的很是直观。。 下面是我发现的怎么改变终端颜色的方法,在archlinux下改变方法和ubuntu和debian的改变方法有一点点不同。

一,改变 普通用户:编辑 .bashrc, 添加 PS1='${arch_chroot:+($arch_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'
二,改变root, :编辑 /etc/bash.bashrc , 添加 alias ls='ls --color=auto'
与 PS1='${arch_chroot:+($arch_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$' 前者使ls出来的是彩色的,好分辨文件类型。。后者使 root@arch:~ 变的彩色

颜色及相关数值:30 (黑色)、31 (红色)、32 (绿色)、33 (黄色)、34 (蓝色)、35 ( 紫红色)、36 (青色)、37 (白色)

注意:在编辑完后要重新打开终端才能生效。。 改变后的效果见附图。。

######################################################################################
方法二:其实可以直接用gentoo的来替换arch的,显示效果会更好。。
1,改变普通用户的:用gentoo中的 .bashrc 文件中的内容替换 .bashrc 里的全部内容
2,改变root用户的:用gentoo 中的 /etc/bash/bashrc 文件中的内容替换 /etc/bash.bashrc 中的全部内容。。
同样是重新打开终端。。效果见附图。。

gentoo的 .bashrc

CODE:
# /etc/skel/.bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !


# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi


# Put your fun stuff here.

gentoo的 /etc/bash/bashrc
CODE:
# /etc/bash/bashrc
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !


# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control. #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

# Enable history appending instead of overwriting. #139609
shopt -s histappend

# Change the window title of X terminals
case ${TERM} in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
;;
screen)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
;;
esac

use_color=false

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions. Use internal bash
# globbing instead of external grep binary.
safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs} ]] \
&& type -P dircolors >/dev/null \
&& match_lhs=$(dircolors --print-database)
[[ \n'${match_lhs} == *\n'"TERM "${safe_term}* ]] && use_color=true

if ${use_color} ; then
# Enable colors for ls, etc. Prefer ~/.dir_colors #64489
if type -P dircolors >/dev/null ; then
if [[ -f ~/.dir_colors ]] ; then
eval $(dircolors -b ~/.dir_colors)
elif [[ -f /etc/DIR_COLORS ]] ; then
eval $(dircolors -b /etc/DIR_COLORS)
fi
fi

if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
else
PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
fi

alias ls='ls --color=auto'
alias grep='grep --colour=auto'
else
if [[ ${EUID} == 0 ]] ; then
# show root@ when we don't have colors
PS1='\u@\h \W \$ '
else
PS1='\u@\h \w \$ '
fi
fi

# Try to keep environment pollution down, EPA loves us.
unset use_color safe_term match_lhs





 

archlinux官方wiki上的說明:

Generalizing colors for all users

If you want to generalize the use of colors for all users in the system, you must modify the /etc/bash.bashrc file and create a /etc/DIR_COLORS file. Here is a possible generalization of the Gentoo color scheme for Arch linux:

/etc/bash.bashrc:

# /etc/bash.bashrc## https://wiki.archlinux.org/index.php/Color_Bash_Prompt## This file is sourced by all *interactive* bash shells on startup,# including some apparently interactive shells such as scp and rcp# that can't tolerate any output.  So make sure this doesn't display# anything or bad things will happen !# Test for an interactive shell.  There is no need to set anything# past this point for scp and rcp, and it's important to refrain from# outputting anything in those cases.if [[ $- != *i* ]] ; then	# Shell is non-interactive.  Be done now!	returnfi# Bash won't get SIGWINCH if another process is in the foreground.# Enable checkwinsize so that bash will check the terminal size when# it regains control.  #65623# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)shopt -s checkwinsize# Enable history appending instead of overwriting.  #139609shopt -s histappendcase ${TERM} in  xterm*|rxvt*|Eterm|aterm|kterm|gnome*)    PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'    ;;  screen)    PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'    ;;esac# Fortune is a simple program that displays a pseudorandom message# from a database of quotations at logon and/or logout;# type: "pacman -S fortune-mod" to install it, then uncomment the# following lines:# if [ "$PS1" ]; then#	/usr/bin/fortune# fi# Set colorful PS1 only on colorful terminals.# dircolors --print-database uses its own built-in database# instead of using /etc/DIR_COLORS.  Try to use the external file# first to take advantage of user additions.  Use internal bash# globbing instead of external grep binary.# Dynamically modified variables. Do not change them!use_color=false# sanitize TERM:safe_term=${TERM//[^[:alnum:]]/?}match_lhs=""[[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"[[ -z ${match_lhs}    ]] 	&& type -P dircolors >/dev/null 	&& match_lhs=$(dircolors --print-database)[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=trueif ${use_color} ; then	# Enable colors for ls, etc.  Prefer ~/.dir_colors #64489	if type -P dircolors >/dev/null ; then		if [[ -f ~/.dir_colors ]] ; then			eval $(dircolors -b ~/.dir_colors)		elif [[ -f /etc/DIR_COLORS ]] ; then			eval $(dircolors -b /etc/DIR_COLORS)		fi	fi	if [[ ${EUID} == 0 ]] ; then		PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '	else		PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '	fi	alias ls='ls --color=auto'	alias dir='dir --color=auto'	alias grep='grep --colour=auto'else	if [[ ${EUID} == 0 ]] ; then		# show root@ when we do not have colors		PS1='\u@\h \W \$ '	else		PS1='\u@\h \w \$ '	fifiPS2='> 'PS3='> 'PS4='+ '# Try to keep environment pollution down, EPA loves us.unset use_color safe_term match_lhs[ -r /etc/bash_completion ] && . /etc/bash_completion

/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 all# 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 colorizableTERM linuxTERM consoleTERM con132x25TERM con132x30TERM con132x43TERM con132x60TERM con80x25TERM con80x28TERM con80x30TERM con80x43TERM con80x50TERM con80x60TERM xtermTERM vt100TERM rxvtTERM rxvt-256colorTERM rxvt-cygwinTERM rxvt-cygwin-nativeTERM rxvt-unicodeTERM rxvt-unicode-256colorTERM rxvt-unicode256# 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=whiteNORMAL 00	# global default, although everything should be something.FILE 00 	# normal fileDIR 01;34 	# directoryLINK 01;36 	# symbolic linkFIFO 40;33	# pipeSOCK 01;35	# socketBLK 40;33;01	# block device driverCHR 40;33;01 	# character device driver# 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.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.jpg 01;35 # image formats.gif 01;35.bmp 01;35.xbm 01;35.xpm 01;35.tif 01;35
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
让debian在命令行终端显示彩色的文件及文件夹
linux PATH环境变量全解析
VIM快捷操作
linux下alias命令详解
linux .bashrc文件修改和生效
linux下的别名设置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服