管道符,作业控制
cat 1.txt | wc -l "|"为管道符,把前面输出的内容传送给后方的wc -l命令
wc -l 统计打印文件的行数
wc -c 统计字符个数
wc -w 统计单词个数
ctrl z暂停一个任务
[root@proxy124 ~]$ sleep 1000
^Z
[1]+ Stopped sleep 1000
jobs查看工作任务
[root@proxy124 ~]$ jobs
[1]+ Stopped sleep 1000
fg [id] 把任务丢到前台运行
[root@proxy124 ~]$ fg 1
sleep 1000
bg [id] 把任务丢到后台运行 也可直接运行sleep 1000 &一次性放到后台执行
[root@proxy124 ~]$ bg 1
[1]+ sleep 1000 &
[root@proxy124 ~]#
shell变量
env 查看系统变量
set 查看系统变量和用户自定义变量
变量名的命名规则:字母,数字下划线,首位不能是数字
变量值有特殊符号的时候用单引号或双引号 例:
[root@proxy124 ~]$ a="a$bc"
[root@proxy124 ~]$ echo $a
a
[root@proxy124 ~]$ a='a$bc'
[root@proxy124 ~]$ echo $a
a$bc
[root@proxy124 ~]$
可看出单引号对某些特殊字符有转义的功能,双引号没有
全局变量export a=111 定义一个全局变量,在该bash下面的子bash将继承该bash下定义的变量,变量向下继承,不可父bash继承子bash。
[root@proxy124 ~]$ a=111
[root@proxy124 ~]$ echo $a
111
[root@proxy124 ~]$ bash
[root@proxy124 ~]$ echo $a
[root@proxy124 ~]$ exit
exit
[root@proxy124 ~]$ export a=111
[root@proxy124 ~]$ echo $a
111
[root@proxy124 ~]$ bash
[root@proxy124 ~]$ echo $a
111
[root@proxy124 ~]$
[root@proxy124 ~]$ pstree | grep sshd
|-sshd-+-sshd---bash---ssh
| |-2*[sshd---bash]
| `-sshd-+-bash-+-bash-+-grep
[root@proxy124 ~]$
环境变量配置文件
层次:系统层次 /etc/profile /etc/bashrc
用户层次 .bash_profile .bashrc
类型:用户登录调用profile里面的内容
执行shell脚本调用bashrc里面的内容
用户登出前要执行的命令可以写在.bash_logout里面
PS1 [\u@\h \W]$ [用户@主机名 相对路径目录]$
PS1 [\u@\h \w]$ [用户@主机名 绝对路径目录]$
PS2 = > 多行输入的时候显示的前提示符