📄 sample-bashrc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><HEAD><TITLE>A Sample .bashrc File</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="Advanced Bash-Scripting Guide"HREF="index.html"><LINKREL="PREVIOUS"TITLE="History Commands"HREF="histcommands.html"><LINKREL="NEXT"TITLE="Converting DOS Batch Files to Shell Scripts"HREF="dosbatch.html"><METAHTTP-EQUIV="Content-Style-Type"CONTENT="text/css"><LINKREL="stylesheet"HREF="common/kde-common.css"TYPE="text/css"><METAHTTP-EQUIV="Content-Type"CONTENT="text/html; charset=iso-8859-1"><METAHTTP-EQUIV="Content-Language"CONTENT="en"><LINKREL="stylesheet"HREF="common/kde-localised.css"TYPE="text/css"TITLE="KDE-English"><LINKREL="stylesheet"HREF="common/kde-default.css"TYPE="text/css"TITLE="KDE-Default"></HEAD><BODYCLASS="APPENDIX"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#AA0000"VLINK="#AA0055"ALINK="#AA0000"STYLE="font-family: sans-serif;"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="histcommands.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="dosbatch.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="APPENDIX"><H1><ANAME="SAMPLE-BASHRC"></A>Appendix K. A Sample <TTCLASS="FILENAME">.bashrc</TT> File</H1><P>The <TTCLASS="FILENAME">~/.bashrc</TT> file determines the behavior of interactive shells. A good look at this file can lead to a better understanding of Bash.</P><P><AHREF="mailto:emmanuel.rouat@wanadoo.fr"TARGET="_top">Emmanuel Rouat</A> contributed the following very elaborate <TTCLASS="FILENAME">.bashrc</TT> file, written for a Linux system. He welcomes reader feedback on it.</P><P>Study the file carefully, and feel free to reuse code snippets and functions from it in your own <TTCLASS="FILENAME">.bashrc</TT> file or even in your scripts.</P><DIVCLASS="EXAMPLE"><HR><ANAME="BASHRC"></A><P><B>Example K-1. Sample <TTCLASS="FILENAME">.bashrc</TT> file</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #=============================================================== 2 # 3 # PERSONAL $HOME/.bashrc FILE for bash-2.05a (or later) 4 # 5 # Last modified: Tue Apr 15 20:32:34 CEST 2003 6 # 7 # This file is read (normally) by interactive shells only. 8 # Here is the place to define your aliases, functions and 9 # other interactive features like your prompt. 10 # 11 # This file was designed (originally) for Solaris but based 12 # on Redhat's default .bashrc file 13 # --> Modified for Linux. 14 # The majority of the code you'll find here is based on code found 15 # on Usenet (or internet). 16 # This bashrc file is a bit overcrowded - remember it is just 17 # just an example. Tailor it to your needs 18 # 19 # 20 #=============================================================== 21 22 # --> Comments added by HOWTO author. 23 # --> And then edited again by ER :-) 24 25 #----------------------------------- 26 # Source global definitions (if any) 27 #----------------------------------- 28 29 if [ -f /etc/bashrc ]; then 30 . /etc/bashrc # --> Read /etc/bashrc, if present. 31 fi 32 33 #------------------------------------------------------------- 34 # Automatic setting of $DISPLAY (if not set already) 35 # This works for linux - your mileage may vary.... 36 # The problem is that different types of terminals give 37 # different answers to 'who am i'...... 38 # I have not found a 'universal' method yet 39 #------------------------------------------------------------- 40 41 function get_xserver () 42 { 43 case $TERM in 44 xterm ) 45 XSERVER=$(who am i | awk '{print $NF}' | tr -d ')''(' ) 46 # Ane-Pieter Wieringa suggests the following alternative: 47 # I_AM=$(who am i) 48 # SERVER=${I_AM#*(} 49 # SERVER=${SERVER%*)} 50 51 XSERVER=${XSERVER%%:*} 52 ;; 53 aterm | rxvt) 54 # find some code that works here..... 55 ;; 56 esac 57 } 58 59 if [ -z ${DISPLAY:=""} ]; then 60 get_xserver 61 if [[ -z ${XSERVER} || ${XSERVER} == $(hostname) || 62 ${XSERVER} == "unix" ]]; then 63 DISPLAY=":0.0" # Display on local host 64 else 65 DISPLAY=${XSERVER}:0.0 # Display on remote host 66 fi 67 fi 68 69 export DISPLAY 70 71 #--------------- 72 # Some settings 73 #--------------- 74 75 ulimit -S -c 0 # Don't want any coredumps 76 set -o notify 77 set -o noclobber 78 set -o ignoreeof 79 set -o nounset 80 #set -o xtrace # Useful for debuging 81 82 # Enable options: 83 shopt -s cdspell 84 shopt -s cdable_vars 85 shopt -s checkhash 86 shopt -s checkwinsize 87 shopt -s mailwarn 88 shopt -s sourcepath 89 shopt -s no_empty_cmd_completion # bash>=2.04 only 90 shopt -s cmdhist 91 shopt -s histappend histreedit histverify 92 shopt -s extglob # Necessary for programmable completion 93 94 # Disable options: 95 shopt -u mailwarn 96 unset MAILCHECK # I don't want my shell to warn me of incoming mail 97 98 99 export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n' 100 export HISTIGNORE="&:bg:fg:ll:h" 101 export HOSTFILE=$HOME/.hosts # Put a list of remote hosts in ~/.hosts 102 103 104 105 #----------------------- 106 # Greeting, motd etc... 107 #----------------------- 108 109 # Define some colors first: 110 red='\e[0;31m' 111 RED='\e[1;31m' 112 blue='\e[0;34m' 113 BLUE='\e[1;34m' 114 cyan='\e[0;36m' 115 CYAN='\e[1;36m' 116 NC='\e[0m' # No Color 117 # --> Nice. Has the same effect as using "ansi.sys" in DOS. 118 119 # Looks best on a black background..... 120 echo -e "${CYAN}This is BASH ${RED}${BASH_VERSION%.*}\ 121 ${CYAN} - DISPLAY on ${RED}$DISPLAY${NC}\n" 122 date 123 if [ -x /usr/games/fortune ]; then 124 /usr/games/fortune -s # makes our day a bit more fun.... :-) 125 fi 126 127 function _exit() # function to run upon exit of shell 128 { 129 echo -e "${RED}Hasta la vista, baby${NC}" 130 } 131 trap _exit EXIT 132 133 #--------------- 134 # Shell Prompt 135 #--------------- 136 137 if [[ "${DISPLAY#$HOST}" != ":0.0" && "${DISPLAY}" != ":0" ]]; then 138 HILIT=${red} # remote machine: prompt will be partly red 139 else 140 HILIT=${cyan} # local machine: prompt will be partly cyan 141 fi 142 143 # --> Replace instances of \W with \w in prompt functions below 144 #+ --> to get display of full path name. 145 146 function fastprompt() 147 { 148 unset PROMPT_COMMAND 149 case $TERM in 150 *term | rxvt ) 151 PS1="${HILIT}[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 152 linux ) 153 PS1="${HILIT}[\h]$NC \W > " ;; 154 *) 155 PS1="[\h] \W > " ;; 156 esac 157 } 158 159 function powerprompt() 160 { 161 _powerprompt() 162 { 163 LOAD=$(uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g") 164 } 165 166 PROMPT_COMMAND=_powerprompt 167 case $TERM in 168 *term | rxvt ) 169 PS1="${HILIT}[\A \$LOAD]$NC\n[\h \#] \W > \ 170 \[\033]0;\${TERM} [\u@\h] \w\007\]" ;; 171 linux ) 172 PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w > " ;; 173 * ) 174 PS1="[\A - \$LOAD]\n[\h \#] \w > " ;; 175 esac 176 } 177 178 powerprompt # This is the default prompt -- might be slow. 179 # If too slow, use fastprompt instead. 180 181 #=============================================================== 182 # 183 # ALIASES AND FUNCTIONS 184 # 185 # Arguably, some functions defined here are quite big 186 # (ie 'lowercase') but my workstation has 512Meg of RAM, so ... 187 # If you want to make this file smaller, these functions can 188 # be converted into scripts. 189 # 190 # Many functions were taken (almost) straight from the bash-2.04 191 # examples. 192 # 193 #=============================================================== 194 195 #------------------- 196 # Personnal Aliases 197 #------------------- 198 199 alias rm='rm -i' 200 alias cp='cp -i' 201 alias mv='mv -i' 202 # -> Prevents accidentally clobbering files. 203 alias mkdir='mkdir -p' 204 205 alias h='history' 206 alias j='jobs -l' 207 alias r='rlogin' 208 alias which='type -all' 209 alias ..='cd ..' 210 alias path='echo -e ${PATH//:/\\n}' 211 alias print='/usr/bin/lp -o nobanner -d $LPDEST' 212 # Assumes LPDEST is defined 213 alias pjet='enscript -h -G -fCourier9 -d $LPDEST' 214 # Pretty-print using enscript 215 alias background='xv -root -quit -max -rmode 5' 216 # Put a picture in the background 217 alias du='du -kh' 218 alias df='df -kTh' 219 220 # The 'ls' family (this assumes you use the GNU ls) 221 alias la='ls -Al' # show hidden files 222 alias ls='ls -hF --color' # add colors for filetype recognition 223 alias lx='ls -lXB' # sort by extension 224 alias lk='ls -lSr' # sort by size 225 alias lc='ls -lcr' # sort by change time 226 alias lu='ls -lur' # sort by access time 227 alias lr='ls -lR' # recursive ls 228 alias lt='ls -ltr' # sort by date 229 alias lm='ls -al |more' # pipe through 'more' 230 alias tree='tree -Csu' # nice alternative to 'ls' 231 232 # tailoring 'less' 233 alias more='less' 234 export PAGER=less 235 export LESSCHARSET='latin1' 236 export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' 237 # Use this if lesspipe.sh exists. 238 export LESS='-i -N -w -z-4 -g -e -M -X -F -R -P%t?f%f \ 239 :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' 240 241 # spelling typos - highly personnal :-) 242 alias xs='cd' 243 alias vf='cd' 244 alias moer='more' 245 alias moew='more' 246 alias kk='ll' 247 248 #---------------- 249 # a few fun ones 250 #---------------- 251 252 function xtitle () 253 { 254 case "$TERM" in 255 *term | rxvt) 256 echo -n -e "\033]0;$*\007" ;; 257 *) 258 ;; 259 esac 260 } 261 262 # aliases... 263 alias top='xtitle Processes on $HOST && top' 264 alias make='xtitle Making $(basename $PWD) ; make' 265 alias ncftp="xtitle ncFTP ; ncftp" 266 267 # .. and functions 268 function man () 269 { 270 for i ; do 271 xtitle The $(basename $1|tr -d .[:digit:]) manual 272 command man -F -a "$i" 273 done 274 } 275 276 function ll() 277 { ls -l "$@"| egrep "^d" ; ls -lXB "$@" 2>&-| egrep -v "^d|total "; } 278 279 function te() # wrapper around xemacs/gnuserv 280 { 281 if [ "$(gnuclient -batch -eval t 2>&-)" == "t" ]; then 282 gnuclient -q "$@"; 283 else 284 ( xemacs "$@" &); 285 fi 286 } 287 288 #----------------------------------- 289 # File & strings related functions: 290 #----------------------------------- 291 292 # Find a file with a pattern in name: 293 function ff() 294 295 { find . -type f -iname '*'$*'*' -ls ; } 296 # Find a file with pattern $1 in name and Execute $2 on it: 297 298 function fe()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -