天天看點

FreeBSD 用BASH 的/etc/bashrc 檔案

FreeBSD系统默认的shell 为sh,使用起来很不方面,所以安装完后就是安装 bash 和修改默认shell为bash

但是bash在没有经过配置之前还是不太好用,下面就是参考了网上的配置后确定下来的 /etc/bashrc 文件内容

并通过修改 home目录下面的 .bashrc 文件,加入

# Source global definitions

if [ -f /etc/bashrc ]; then

        . /etc/bashrc

fi

使用户能够在登录时自动加载配置

文件  /etc/bashrc

#export env

export LANG=zh_CN.UTF-8

export CLICOLOR=1

export TERM=xterm-color

export LSCOLORS=Exfxcxdxbxegedabagacad

export LD_LIBRARY_PATH=/usr/local/lib

export http_proxy=http://10.0.0.2:8080

export PACKAGEROOT=http://xx.xxx.xxx

#----------

# 一些设置

#----------

ulimit -S -c 0          # 不需要任何coredump

set -o notify

set -o noclobber

set -o ignoreeof

set -o nounset

set -o vi                    # 在命令行中通过ESC键进入编辑模式,可使用一些vi里的命令来编辑当前命令行,对于一些长命令非常方便

set -o ktrace            # 对于调试来说非常有用

# 使能选项:

shopt -s cdspell

shopt -s cdable_vars

shopt -s checkhash

shopt -s checkwinsize

shopt -s mailwarn

shopt -s sourcepath

shopt -s no_empty_cmd_completion  # 仅限于bash>=2.04

shopt -s cmdhist

shopt -s histappend histreedit histverify

shopt -s extglob             # 对于complete命令(按情况补全)来说是必要的

# 禁用选项:

shopt -u mailwarn

unset MAILCHECK         # 当有邮件到达时, 我不希望我的shell提示我

export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'

export HISTIGNORE="&:bg:fg:ll:h"

export HOSTFILE=$HOME/.hosts    # 将远端主机的列表放入~/.hosts

#-------------------

# 个人的别名

#-------------------

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

# -> 防止偶然的文件误操作.

alias mkdir='mkdir -p'

alias h='history'

alias j='jobs -l'

alias r='rlogin'

alias which='type -all'

alias ..='cd ..'

alias path='echo -e ${PATH//:/\\n}'

alias print='/usr/bin/lp -o nobanner -d $LPDEST'   # 假设LPDEST被定义

alias pjet='enscript -h -G -fCourier9 -d $LPDEST'  # 使用enscript的漂亮的打印

alias background='xv -root -quit -max -rmode 5'    # 将一张图片作为背景

alias du='du -kh'

alias df='df -kh'

# 'ls'家族 (假定使用GNU ls)

alias ls='ls -hF -G'          # 为识别的文件类型添加颜色

alias la='ls -Al'                 # 显示隐藏文件

alias lx='ls -lXB'               # 按扩展名排序

alias ll='ls -l'

alias lk='ls -lSr'                # 按尺寸排序

alias lc='ls -ltcr'                # 按修改时间排序

alias lu='ls -ltur'               # 按访问时间排序

alias lr='ls -lR'                  # 递归ls

alias lt='ls -ltr'                   # 按日期排序

alias lld='ls -l "[email protected]"| egrep "^d" ; ls -lXB "[email protected]" 2>&-| egrep -v "^d|total "'

alias lm='ls -al |more'       # 管道给'more'

alias tree='tree -Csu'        # 'ls'的另一种好方法

alias more='more -r'

alias less='less -r'

# 裁减'less'

alias more='less'

export PAGER=less

#export LESSCHARSET='latin1'

#export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # 如果lesspipe.sh存在, 就用这个

#export LESS='-i -N -w  -z-4 -g -e -M -X -F -R -P%t?f%f :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'

# 拼写错误 

alias xs='cd'

alias vf='cd'

alias moer='more'

alias moew='more'

alias kk='ll'

function swap()         # 交换两个文件名

{

    local TMPFILE=tmp.$$

    mv "$1" $TMPFILE

    mv "$2" "$1"

    mv $TMPFILE "$2"

}

function cuttail() # 在文件中切掉n行, 默认为10行

{

    nlines=${2:-10}

    sed -n -e :a -e "1,${nlines}!{P;N;D;};N;ba" $1

}

function lowercase()  # 将文件名转换为小写

{

    for file ; do

        filename=${file##*/}

        case "$filename" in

        */*) dirname==${file%/*} ;;

        *) dirname=.;;

        esac

        nf=$(echo $filename | tr A-Z a-z)

        newname="${dirname}/${nf}"

        if [ "$nf" != "$filename" ]; then

            mv "$file" "$newname"

            echo "lowercase: $file --> $newname"

        else

            echo "lowercase: $file not changed."

        fi

    done

}

# 杂项工具:

function repeat()       # 重复n次的命令

{

    local i max

    max=$1; shift;

    for ((i=1; i <= max ; i++)); do  # --> C风格的语法

        eval "[email protected]";

    done

}

function ask()

{

    echo -n "[email protected]" '[y/n] ' ; read ans

    case "$ans" in

        y*|Y*) return 0 ;;

        *) return 1 ;;

    esac

}

pskill()

{

        local pid

        pid=$(ps -ax | grep $1 | grep -v grep | awk '{ print $1 }')

        echo -n "killing $1 (process $pid)..."

        kill -9 $pid

        echo "slaughtered."

}