1 / 14

第 7 章 定制用户环境

第 7 章 定制用户环境. 内容概要. 描述 login profile (登陆环境)的作用 更改 PATH 与 PS1 变量 使用 shell history (历史命令)机制 设置 aliases (别名) 来使用常用命令. 登陆环境文件. /etc/environment. root. login: team01 team01's Password: $. /etc/profile. root. $HOME/.profile. User. $HOME/. kshrc. User. /etc/environment 举例.

len-hill
Download Presentation

第 7 章 定制用户环境

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第7章定制用户环境

  2. 内容概要 • 描述login profile(登陆环境)的作用 • 更改 PATH与 PS1变量 • 使用shellhistory(历史命令)机制 • 设置 aliases(别名) 来使用常用命令

  3. 登陆环境文件 /etc/environment root login: team01 team01's Password: $ /etc/profile root $HOME/.profile User $HOME/.kshrc User

  4. /etc/environment 举例 $ cat /etc/environment # WARNING: This file is only for establishing # environmentvariables. Execution of commands #from this file or anylines other than specified #above may cause failure of the initialization #process. PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java131/jre/bin:/usr/java131/bin TZ=EST5EDT LANG=en_US LOCPATH=/usr/lib/nls/loc NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat

  5. /etc/profile 举例 $ cat /etc/profile # System-wide profile. All variables set here may be overridden by # a user's personal .profile file in their $HOME directory. However # all commands here will be executed at login regardless. trap "" 1 2 3 readonly LOGNAME # Automatic logout (after 120 seconds inactive) TMOUT=120 # The MAILMSG will be printed by the shell every MAILCHECK seconds # (default 600) if there is mail in the MAIL system mailbox. MAIL=/usr/spool/mail/$LOGNAME MAILMSG="[YOU HAVE NEW MAIL]" # If termdef command returns terminal type (i.e. a non NULL value), # set TERM to the returned value, else set TERM to default lft. TERM_DEFAULT=lft TERM=`termdef` TERM=${TERM:-$TERM_DEFAULT} export LOGNAME MAIL MAILMSG TERM TMOUT trap 1 2 3

  6. 环境变量 (1 of 2) LOGNAME 该变量保存用户的用户名. 能够被很多命令读取. 无法改变该变量的值 (只读变量) TMOUT 该变量保存登陆系统前无任何操作,终端自动退出的时间值 MAIL 该变量保存用户存储邮件的文件名 用户所使用的终端类型. 该变量由定向显示的应用所使用,例如vi或者smit TERM

  7. .profile 举例 • $ cat .profile • PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:. • PS1=' $PWD => ' • ENV="$HOME/.kshrc" • export PATH PS1 ENV • if [ -s "$MAIL" ] • then • echo "$MAILMSG" • fi 每次启动新的Korn Shell都会执行该文件。

  8. 环境变量 (2 of 2) PATH 由冒号隔开的一列目录,shell会在这些目录下寻找命令:PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:. PS1 一级系统提示符 (默认为 $). 以下设置能够显示主机名或者当前工作目录:PS1="$(hostname), "'$PWD: ' ENV 该变量指向包含Korn shell设置文件: ENV="$HOME/.kshrc"

  9. .kshrc 举例 $ cat .kshrc # set up the command recall facility set -o vi # set up a few aliases alias ll='ls -l' alias p='ps -f' alias up='cd ..'

  10. ksh 特色 –别名 $ alias p='ps -ef' $ alias ll='ls -l' $ alias history='fc -l' ll='ls -l' p= 'ps -ef' r= 'fc -e -' 显示所有定义的别名

  11. ksh 特色 –使用别名 $ll -rw-r--r-- 1 joe staff 524 Sep 19 11:31 fleas -rw-r--r-- 1 joe staff 1455 Jan 23 17:18 walrus $ unalias ll $ll ksh: ll: not found alias ll='ls -l' 删除已定义别名

  12. ksh 特色 –历史命令 最后使用的128条命令存储以下在文件中, 使用 fc 命令查看 $HOME/.sh_history $ fc -l 2 cd /home/payroll 3 ls -l 4 mail

  13. 课堂练习 • 你会使用哪个文件来定制你的用户环境?为什么? • 以下定义的变量在系统中有什么作用? PS1: TERM: PATH:

  14. 课堂练习答案 • 你会使用哪个文件来定制用户环境,为什么? $HOME/.profile 该文件会覆盖系统环境定制文件 /etc/profile. 2. 以下定义的变量在系统中有什么作用? PS1: 一级系统提示符 (用户自己的提示符) TERM: 终端类型 PATH: 搜索可执行命令的目录

More Related