笔记内容:
8.6 管道符和作业控制
8.7/8.8 shell变量
8.9 环境变量配置文件
扩展
bashrc和bash_profile的区别 http://ask.apelearn.com/question/7719
简易审计系统: http://www.68idc.cn/help/server/linux/2014042190951.html
关于PROMPT_COMMAND环境变量的含义 http://www.linuxnote.org/prompt_command-environment-variables.html
一、管道符和作业控制

[root@aminglinux-01 ~]# jobs //查看任务
[1]- 已停止 vim 1.txt
[2]+ 已停止 vim aa.txt
[root@aminglinux-01 ~]# fg //sleep 800任务丢到前台
sleep 800
^Z
[3]+ 已停止 sleep 800
[root@aminglinux-01 ~]# bg //sleep 800任务丢到后台执行
[3]+ sleep 800 &
[root@aminglinux-01 ~]# fg 1 //把任务1放到前台
vim 1.txt
[1]+ 已停止 vim 1.txt
[root@aminglinux-01 ~]# bg 1 //丢到后台并执行
[1]+ vim 1.txt &
[root@aminglinux-01 ~]# jobs //适用于本回话
[1]- 已停止 vim 1.txt
[2]+ 已停止 vim aa.txt
[3] 运行中 sleep 800 &
# sleep 100& //命令&直接丢到后台执行

#ps –aux | grep sleep //查看sleep进程

二、shell变量

#env //查看系统常用变量

#set //查看系统和用户自定义变量
自定义变量a=111:
#a=111
#echo $a
#set | grep 111
#set | less


变量名规则:字母、数字下划线,首位不能为数字

变量值有特殊符号用单引号括起来
变量的累加

export 变量名=变量值
全局变量仅在子shell可用—用pstree查看子shell
#w //查看用户登录情况
#echo $SSH_TTY

#pstree //查看子shell
#export dh=123123
#bash
#unset 变量名 //取消变量

三、环境变量配置文件

系统文件:/etc 用户登录
用户文件:.bash 系统执行
PS1 //etc/bashrc定义的变量PS1, [root@aminglinux-01 ~]这个就是PS1的显示内容
#echo $PS1 //查看PS1变量值
PS2 //小终端 >

#for i in `seq 1 100`

#PS1='[\u@\h \w]\$' //路径W改成w后,linux系统显示绝对路径

#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ ' //带颜色显示

四、简易审计系统
1.
mkdir -p /usr/local/records/
chmod 777 /usr/local/records/
chmod +t /usr/local/records/
[root@aminglinux-01 root]# mkdir -p /usr/local/records/
[root@aminglinux-01 root]# chmod 777 /usr/local/records/
[root@aminglinux-01 root]# ^Cmod +t /usr/local/records/
2.
vi /etc/profile 在最后添加下面的代码
if [ ! -d /usr/local/records/${LOGNAME} ]
then
mkdir -p /usr/local/records/${LOGNAME}
chmod 300 /usr/local/records/${LOGNAME}
fi
export HISTORY_FILE="/usr/local/records/${LOGNAME}/bash_history"
export PROMPT_COMMAND='{ date "+%Y-%m-%d %T ##### (who am i |awk "{print \1" "$2" "$5}") #### (history 1 | { read x cmd; echo "cmd"; })"; } >>$HISTORY_FILE'
网友评论