Test Header HTML Code

配置Shell

 

为了便于高效工作,我们可以调整一下Shell的配置.

许多配置文件支持配置Shell.

  • /etc/profile - 为所有用户配置环境信息,每次登录系统的时候执行一次.这个文件一般配置许多环境变量,比如路径,Mailbox位置,历史文件大小. /etc/profile 收集/etc/profile.d文件夹下面的配置文件信息(应该是顺便执行一遍)

  • /etc/bashrc - 对所有使用bash shell的用户有效。不过配置信息可能会被每个用户的~/.bashrc覆盖.

  • ~/.bash_profile - 每个用户登录时执行一次,一般也就是设置一些环境变量,并执行一下.bashrc文件

  • ~/.bashrc 每次用户打开一个新的bash shell 时,运行一次。这是个人定制bash shell的最佳配置文件。

  • ~/.bash_logout -在退出时(最后一个bash shell)时执行。

/etc/profile or /etc/bashrc files,必须是root用户.

配置 Prompt

即在接受命令输入前的Shell提示文本;由PS1环境变量设置. If your shell requires additional input, it uses the values of PS2, PS3, and PS4.

一般设置为: your user name, your hostname, and the base name of your current working directory. 如:

[chris@myhost bin]$

You can use several special characters (indicated by adding a backslash to a variety of letters) to include different information in your prompt. These can include your terminal number, the date, and the time, as well as other pieces of information. Here are some examples:

  • \! - Shows the current command history number. This includes all previous commands stored for your user name.

  • \# - Shows the command number of the current command. This includes only the commands for the active shell.

  • \$ - Shows the user prompt ($) or root prompt (#), depending on which user you are.

  • \W - Shows only the current working directory base name. For example, if the current working directory was /var/spool/mail, this value would simply appear as mail.

  • \[ - Precedes a sequence of nonprinting characters. This could be used to add a terminal control sequence into the prompt for such things as changing colors, adding blink effects, or making characters bold. (Your terminal determines the exact sequences available.)

  • \] - Follows a sequence of nonprinting characters.

  • \\ - Shows a backslash.

  • \d - Displays the day, month, and number of the date. For example: Sat Jan 23.

  • \h - Shows the hostname of the computer running the shell.

  • \n - Causes a newline to occur.

  • \nnn - Shows the character that relates to the octal number replacing nnn.

  • \s - Displays the current shell name. For the bash shell, the value would be bash.

  • \t - Prints the current time in hours, minutes, and seconds (for example, 10:14:39).

  • \u - Prints your current user name.

  • \w - Displays the full path to the current working directory.

Tip 

If you are setting your prompt temporarily by typing at the shell, you should put the value of PS1 in quotes. For example, you could type export PS1="[\t \w]\$ " to see a prompt that looks like this: [20:26:32 /var/spool]$.

To make a change to your prompt permanent, add the value of PS1 to your .bashrc file in your home directory (assuming that you are using the bash shell). There may already be a PS1 value in that file that you can modify. Refer to the Bash Prompt HOWTO (www.tldp.org/HOWTO/Bash-Prompt-HOWTO) for information on changing colors, commands, and other features for your bash shell prompt.

Adding Environment Variables 添加环境变量

You may consider adding a few environment variables to your .bashrc file. These can help make working with the shell more efficient and effective:

  • TMOUT - 设置Shell的最大空闲时间,超过此时间,则自动退出。这主要是出于安全考虑,比如设置TMOUT=1800 (即 30 分钟).

  • PATH -在运行命令时从该环境变量中包含的文件夹下查找。比如:PATH=$PATH:/getstuff/bin ; export PATH

Adding Aliases添加别名

给将常用的命令命别名,比如:

alias p='pwd ; ls -CF'
alias rm='rm -i'

posted on 2010-04-07 16:49  宁静的水泡  阅读(1904)  评论(0编辑  收藏  举报

导航

Test Rooter HTML Code