您的位置:首页 > 其它

管道符、作业控制、变量

2018-01-12 02:03 246 查看

管道符

将前一个命令的输出作为后一个命令的输入
cat 1.txt|wc -l 显示 1.txt 行数,先查看内容,再统计行数

作业控制

bg 将当前程序或进程调取到后台运行(挂起)
fg 将当期程序或进程调取到前台进行
jobs 查看后台被挂起的进程
ctrl +z 暂停当期进程
ctrl +c 结束当前进程
ps 查看系统进程数
kill 杀死系统进程(指定PID)
killall 杀死系统进程(指定名称)

变量

PATH HOME PWD LOGNAME

env命令 获取系统预设的全部系统变量(系统变量默认都是大写的)

set 多了很多变量,并且包括用户自定义的变量

自定义变量



变量名规则:字母、数字下划线,首位不能为数字
变量中有特殊字符,千万记得要两边加单引号
[root@aminglinux01 ~]# a='a b c '
[root@aminglinux01 ~]# echo $a
a b c
[root@aminglinux01 ~]# a= "a b c d "
-bash: a b c d : 未找到命令
[root@aminglinux01 ~]# a= "a b c d"
-bash: a b c d: 未找到命令
[root@aminglinux01 ~]# a='a$bc'
[root@aminglinux01 ~]# echo $a
a$bc

变量的累加

这是个很有意思的例子



全局变量

(当前shell的子shell继承当前父shell,即孙子有儿子的样子,儿子有你的样子,但你爸爸不会有你的样子)
[root@aminglinux01 ~]# export aming=linux #声明全局变量
[root@aminglinux01 ~]# echo $aming
linux
[root@aminglinux01 ~]# bash #进入子shell
[root@aminglinux01 ~]# echo aming
aming
[root@aminglinux01 ~]# export aming=linux #进子shell的子shell
[root@aminglinux01 ~]# bash
[root@aminglinux01 ~]# echo aming
aming #子shell 均可生效

取消全局变量

[root@aminglinux01 ~]# unset aming
[root@aminglinux01 ~]# echo $aming #取消后不生效

环境变量配置文件

/etc/profile 用户环境变量,交互、登录才执行
/etc/bashrc 用户不登录,执行shell 就生效

只针对当前用户下的变量:
~/.bashrc
~/.bash_profile
~/.bash_history 用户历史记录记录
~/.bash_logout 用户退出需要做的操作

vim .bash_profile
. .bash_profile 或者 source .bash_profile使用户的.bash_profileshengxiao
===>会去自动调用 .bashrc===========>再会去自动调用/etc/bashrc

vim /etc/bashrc 配置PS1
PS1 显示用户登录时的信息

[root@aminglinux01 ~]# cd /etc/sysconfig/network-scripts/
[root@aminglinux01 network-scripts]# echo $PS1
[\u@\h \W]\$ # 当前用户,主机名,相对路径
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息