正在加载...

优化Hostmonster运行环境

六月 12th, 2008

Bash 配置文件

当我们要求登录Shell的时候,系统将会验证权限,设置运行环境并启动用户交互界面,在unix系统下,系统启动时一般会加载位于主目录或 /ect 目录下的bash文件。如果bash文件存在,就会接着依次查找 ~/.bash_profile, ~/.bash_login and ~/.profile, 并加载文件里的配置,如果这些文件都不存在,就使用 /etc/bashrc 

修改命令行参数

export LD_LIBRARY_PATH=$HOME/lib/
export PATH="$HOME/bin:$PATH"
source ~/.bash_profile

修改命令行提示符

只需要修改 ~/.bash_profile 文件中的PS1 变量.想要修改立即生效, 运行命令

. ~/.bash_profile

下面是命令行提示符中可用的参数意义

\a     an ASCII bell character (07)
\d     the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format}  the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation.
\e     an ASCII escape character (033)
\h     the hostname up to the first `.'
\H     the hostname
\j     the number of jobs currently managed by the shell
\l     the basename of the shell's terminal device name
\n     newline
\r     carriage return
\s     the name of the shell, the basename of $0 (the portion following the final slash)
\t     the current time in 24-hour HH:MM:SS format
\T     the current time in 12-hour HH:MM:SS format
\@     the current time in 12-hour am/pm format
\A     the current time in 24-hour HH:MM format
\u     the username of the current user
\v     the version of bash (e.g., 2.00)
\V     the release of bash, version + patchelvel (e.g., 2.00.0)
\w     the current working directory
\W     the basename of the current working directory
\!     the history number of this command
\#     the command number of this command
\$     if the effective UID is 0, a #, otherwise a $
\nnn   the character corresponding to the octal number nnn
\\     a backslash
\[     begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]     end a sequence of non-printing characters

The command number and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file, while the command number is the position in the sequence of commands executed during the current shell session. After the string is decoded, it is expanded via parameter expansion, command substitution, arithmetic expansion, and quote removal.

一些有用的命令行提示符配置
export PS1='\[\033[1;33m\]\u\[\033[1;37m\]@\[\033[1;32m\]\h\[\033[1;37m\]:\[\033[1;31m\]\w \[\033[1;36m\]\$ \[\033[0m\]'
user@host:~/bin/tools $
export PS1="\e[1;31m[\h]$NC \W > \[\033]0;\${TERM} [\u@\h] \w\]"
[lifesaver] tools >
export PS1="\n\e[1;37m[\e[0;32m\u\e[0;35m@\e[0;32m\h\e[1;37m]\e[1;37m[\e[0;31m\w\e[1;37m]\n$ \e[0m"
[user@host][~/bin/tools]
$
export PS1="\n[$?]\e[1;37m[\e[0;32m\u\e[0;35m@\e[0;32m\h\e[1;37m]\e[1;37m[\e[0;31m\w\e[1;37m]($SHLVL:\!)\n\[\033[0m\]\$ "
[0][user@host][~/bin/tools](1:2130) 
export PS1='[\u@\h:\w]\$ '

设置登录欢迎信息

在你的 ~/.bash_profile 添加一些可以执行的命令,在你登录的时候就会直接显示了

# 显示文本
echo 'hello'
# 显示日历
cal $(date +"%m") $(date +"%Y")
# 显示机器状态
echo -e "Machine stats"; uptime
procinfo|head -n 13|tail -n 11

为目录列表添加颜色

使目录,普通文件,压缩文件,链接文件显示不同的颜色

命令行:

vim ~/.bash_profile

复制下面的代码到 ~/.bash_profile:

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias rm 'mv \!* ~/TRASH'
    #alias dir='ls --color=auto --format=vertical'
    #alias vdir='ls --color=auto --format=long'
fi

编辑你自己的运行环境配置

命令行

vi ~/.bashrc

添加如下代码

export PATH=~/bin:$PATH

如果你使用 .bash_profile

命令行:

vi ~/.bash_profile

添加如下代码

. .bashrc

使用以下命令是修改立即生效.

. .bashrc

使用自己的运行目录

如果你使用上面介绍的命令,在你的根目录下将会生成许多文件夹,如果你不喜欢这种凌乱的样子,你可以创建一个目录用来存放执行目录和运行时库:

mkdir packages

设置PATH 和 LD_LIBRARY_PATH

export LD_LIBRARY_PATH=$HOME/packages/lib/
export PATH="$HOME/packages/bin:$PATH"

完整的例子请查看Unix account setup

禁止新邮件提醒

添加以下代码到 .bash_profile.

unset MAILCHECK

相关阅读:



我要留言


  • 热门文章

  • 最近评论

  • 最近文章

  • 分类杂谈

  • 标签

    Appdrop Google Google App Engine IT Micolog Python SCapture ajax apple appspot best gae bug buzz db gae gfw google google-app-engine-toturial hostmonster html5 linux live micolog picasa plugin python script skpye skydriver svn system taobao tutorial ubuntu vmware vs2008 windows live writer 乐一个 地震 女装 王石 现代寓言故事 生活 艺术 范跑跑 输入法 郭跳跳
  • 归档

  • 友情链接