Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15554
  • 博文数量: 18
  • 博客积分: 370
  • 博客等级: 一等列兵
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-16 09:25
文章分类

全部博文(18)

文章存档

2011年(18)

我的朋友
最近访客

分类: LINUX

2011-03-18 15:59:24

1. Bash配置文件总揽
 
/etc/bashrc         整个系统的别名和功能;
/etc/profile        整个系统的环境参数和启动程序;
$HOME/.bashrc       用户的别名和功能;
$HOME/.bash_profile 用户的环境参数和启动程序;
$HOME/.inputrc      主要绑定数值和其他位元数值; 
 
2. Bash 配置文件详解
 
2.1 /etc/profile 

# /etc/profile

# System wide environment and startup programs
# --整个系统的环境和启动程序
#
# Functions and aliases go in /etc/bashrc
# --/etc/bashhrc中包含功能和别名
#
# This file sets up the following features and programs:
# --这个文档指定下列功能:
#
#   o path                         --路径
#   o prompts                      --提示符
#   o a few environment variables  --几个环境参数
#   o colour ls                    --ls 的颜色
#   o less behaviour               --设定less的功能
#   o rxvt
#
# Users can override these settings and/or add others in their
# $HOME/.bash_profile
# 用户可在 $HOME/.bash_profile 中取消这些设定和(或)增加其他设定


# set a decent path
# 设定可行的路径

PATH="$PATH:/usr/X11R6/bin: $HOME/bin:."

# notify the user: login or non-login shell. If login, the prompt is
# coloured in blue; otherwise in magenta. Root's prompt is red.
# See the Colour-ls mini  HOWTO  for an explanation of the escape codes.
# 通知用户:登陆(login)或不登陆(non-login)的外围程序(shell)。
# 如果登陆,则提示符为蓝色,否则为紫剪色。Root的提示符为红色。
# 参阅Colour-ls mini  HOWTO 中escape codes的使用解释。

USER=`whoami`
if [ $LOGNAME = $USER ] ; then
  COLOUR=44  # blue --蓝色
else
  COLOUR=45  # magenta --紫红色
fi

if [ $USER = 'root' ] ; then
  COLOUR=41  # red --红色
  PATH="$PATH:/usr/local/bin"
fi

ESC="\033"
PROMPT='\h'    # hostname --主机名
STYLE=';1m'    # bold --粗体
# PROMPT='\u'  # username --用户名
# STYLE='m'    # plain --一般字体
PS1="\[$ESC[$COLOUR;37$STYLE\]$PROMPT:\[$ESC[37;40$STYLE\]\w\\$ "
PS2="> "

# no core dumps, please
# 请勿转存信息

ulimit -c 0

# set umask
# 设定umask

if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
  umask 002
else
  umask 022
fi

# a few variables
# 几项变数

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"  # sendmail, postfix, smail
# MAIL="$HOME/Mailbox"        # qmail
NNTPSERVER=news.myisp.it      # put your own here
VISUAL=jed
EDITOR=jed
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
HISTFILESIZE=1000
export PATH PS1 PS2 USER LOGNAME MAIL NNTPSERVER
export VISUAL EDITOR HOSTNAME HISTSIZE HISTFILESIZE

# enable colour ls
# 设定ls的颜色

eval `dircolors /etc/DIR_COLORS -b`
export LS_OPTIONS='-s -F -T 0 --color=yes'

# customize less
# 设定less

LESS='-M-Q'
LESSEDIT="%E ?lt+%lt. %f"
LESSOPEN="| lesspipe.sh %s"
LESSCHARDEF=8bcccbcc13b.4b95.33b. # show colours in ls -l | less
# LESSCHARSET=latin1
PAGER=less
export LESS LESSEDIT LESSOPEN VISUAL LESSCHARDEF

# fix the backspace key in rxvt/xterm
# 设定rxvt/xterm中的退后键

CTRL_H="\010"
NULL_STRING=" $CTRL_H" # space + backspace
if [ "$NULL_STRING" != "" ] ; then
  stty erase ^?
else
  stty erase ^H
fi

# set xterm title: full path
case $TERM in
  xterm*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    ;;
esac

for i in /etc/profile.d/*.sh ; do
  if [ -x $i ]; then
    . $i # beware - variables and aliases might get overridden!
  fi
done

# call fortune, if available  --如有fortune
if [ -x /usr/games/fortune ] ; then
  echo ; /usr/games/fortune ; echo
fi



2.2 /etc/bashrc

# /etc/bashrc

# System wide functions and aliases
# 整个系统的功能和别名
#
# Environment stuff goes in /etc/profile
# /etc/profile中的环境参数
#
# Insert PS1 definitions here if you experience problems.
# 如有问题可把PS1的参数放在此处

export CDPATH="$CDPATH:

# common aliases --共同别名

alias cp='cp -i'
alias l=less
alias ls="ls $LS_OPTIONS"
alias mv='mv -i'
alias rm='rm -i'
alias rmbk='/bin/rm -f .*
alias u='cd ..'
alias which="type -path"
alias x=startx

# A few useful functions --几项有用的功能

c ()    # cd to the new directory and list its contents
{
  cd $1 ; ls
}

inst()  # Install a .tar.gz archive in current directory --在当前目录中建立.tar.gz储存库
{
  if [ $# != 0 ]; then tar zxvf $1; fi
}

cz()    # List the contents of a .zip archive --列出.zip的?容
{
  if [ $# != 0 ]; then unzip -l $*; fi
}

ctgz()  # List the contents of a .tar.gz archive --列出.tar.gz的?容
{
  for file in $* ; do
    tar ztf ${file}
  done
}

tgz()   # Create a .tgz archive a la zip. --建立压缩档.tgz
{
  if [ $# != 0 ]; then
    name=$1.tar; shift; tar -rvf ${name} $* ; gzip -9 ${name}
  fi
}

crpm()  # list information on an .rpm file --列出.rpm档的?容
{
  if [ $# != 0 ]; then rpm -qil $1 | less; fi
}


2.3  $HOME/.bashrc
# $HOME/.bashrc
# Source global definitions

if [ -f /etc/bashrc ]; then
  . /etc/bashrc
fi

# this is needed to notify the user that they are in non-login shell
# 需要以下设定,以便通知处于不登陆(non-login)外围程序(shell)中的用?

if [ "$GET_PS1" = "" ] ; then
  COLOUR=45; ESC="\033"; STYLE=';1m';  # STYLE='m'
  USER=`whoami`
  export PS1="\[$ESC[$COLOUR;37$STYLE\]$USER:\[$ESC[37;40$STYLE\]\w\\$ "
fi

# personal aliases
# 个人别名

alias backup='tar -Mcvf /dev/fd0'
alias dial='eznet up myisp'
alias f='cd
alias hangup='eznet down'
alias lyx='lyx -width 580 -height 450'
alias restore='tar -M -xpvf /dev/fd0'

# personal functions
# 几个个人使用的功能

xj()    # Launch xjed and a file in background --在背景启动xjed和文档
{
  xjed $1 &
}


2.4 $HOME/.bash_profile

# $HOME/.bash_profile

# User specific environment and startup programs
# 用户特定的环境参数和启动程式
#
# This file contains user-defined settings that override
# those in /etc/profile
# 这个文档中存有用户自定的设置,可取代/etc/profile 中的数值
#
# Get aliases and functions
# 设定别名和功能
#
if [ -f  then
  GET_PS1="NO"  # don't change the prompt colour --不改变提示符的颜色
  .
fi

# set a few `default' directories
# 设定几?“默认”目录

export CDPATH="$CDPATHHOME:$HOME/text:$HOME/text/geology"


2.5 $HOME/.inputrc
 
# $HOME/.inputrc

# key bindings
# 主要绑定

"\e[1
"\e[3
"\e[4
# (F1 .. F5) are "\e[[A" ... "\e[[E"
# (F1 .. F5) 分?为 "\e[[A" ... "\e[[E"

"\e[[A": "info \C-m"

set bell-style visible          # please don't beep
                                # 喇叭不发声
set meta-flag On                # allow 8-bit input (i.e, accented letters)
                                # 允许8-位元输入(例如重音字符)注:用于欧洲

set convert-meta Off            # don't strip 8-bit characters
                                # 不取消8-位元字符
set output-meta On              # display 8-bit characters correctly
                                # 正确显示8-位元字符
set horizontal-scroll-mode On   # scroll long command lines
                                # 长指令行自动翻转
set show-all-if-ambiguous On    # after TAB is pressed
                                # 按TAB键


--------------------------------------------------------------------------------

设定下列参数使 backspace 和 delete 两键在xterm 和其他X11应用正常:

在.xinitrc中添加:
usermodmap=$HOME/.Xmodmap
xmodmap $usermodmap

在.Xmodmap中添加:
keycode 22 = BackSpace
keycode 107 = Delete

以上就设定了主控台的参数。要修改xterm,则更改如下:
在.Xdefaults中增添:
xterm*VT100.Translations: #override BackSpace: string(0x7F)\n\
        Delete:        string(0x1b) string("[3
        Home:          string(0x1b) string("[1
        End:           string(0x1b) string("[4
        Ctrlrior:     string(0x1b) string("[40
        CtrlNext:      string(0x1b) string("[41

nxterm*VT100.Translations: #override BackSpace: string(0x7F)\n\
        Delete:        string(0x1b) string("[3
        Home:          string(0x1b) string("[1
        End:           string(0x1b) string("[4
        Ctrlrior:     string(0x1b) string("[40
        CtrlNext:      string(0x1b) string("[41


不要以为呃些设定在每个应用中都可正常运作。例如,在xterm中运行joe,有些键位就不起作用;运行rxvt也有相同的问题。
阅读(320) | 评论(0) | 转发(0) |
0

上一篇:初识Bash

下一篇:JQuery常用方法一览

给主人留下些什么吧!~~