管道符 把前面命令的结果输出给后面执行
[root@hanlin lvm]# cat 1.txt
 22222\33333
 22222;\33333
 222333444444
 [root@hanlin lvm]# cat 1.txt |grep '3' (把cat 1.txt的结果中的包含3
的内容过滤出来输出)
 22222\33333
 22222;\33333
 222333444444
  
[root@hanlin lvm]# ls |wc -l (列出目录,数一数多少个文件)
 6
  
作业控制 fg (foreground前台)bg(background后台)
[root@hanlin lvm]# top
[root@hanlin lvm]# vim 1.txt
[root@hanlin lvm]# vmstat 1(列出临时停止的任务)
 [1]+ 已停止 vmstat 1
 [2]- 已停止 vim 1.txt
  
root@hanlin lvm]# touch 2.txt
 [root@hanlin lvm]# fg 1 (调用临时停止的任务1)
 vmstat 1
 1 0 10476 293168 244 1168020 0 0 0 11 7687 6057 0 0 100 0 0
 0 0 10476 292716 248 1168020 0 0 0 9 355 225 0 1 98 0 0
 0 0 10476 292668 248 1168020 0 0 0 0 98 72 0 0 100 0 0
 ^Z
 [1]+ 已停止 vmstat 1(ctrl+z临时停止,ctrl+c中断命令)
 [root@hanlin lvm]# fg 2
 vim 1.txt
[2]+ 已停止 vim 1.txt
[root@hanlin lvm]# jobs (显示已经停止的程序命令列表)
 [1]+ 已停止 vmstat 1 
 [2]- 已停止 vim 1.txt
  
[root@hanlin lvm]# bg 1 (把jobs里面的任务放在后台执行,fg 1调回前台再停止ctrl+z 或者ctrl+c,只有调回前台才可以关闭或者临时终止,后台程序运行中可以执行命令)
 [1]- vmstat 1 &
 [root@hanlin lvm]# 0 0 10472 292768 252 1168036 0 0 0 72 15294 11699 0 0 100 0 0
 0 0 10472 292768 252 1168036 0 0 0 0 171 118 0 1 99 0 0
 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
 1 0 10472 292752 252 1168036 0 0 0 0 146 107 0 0 100 0 0
  
shell
[root@hanlin lvm]# env (查看系统内置的环境变量)
 XDG_SESSION_ID=1
 HOSTNAME=hanlin
 SELINUX_ROLE_REQUESTED=
 TERM=xterm
 SHELL=/bin/bash
 HISTSIZE=1000
 SSH_CLIENT=192.168.3.99 63749 22
 SELINUX_USE_CURRENT_RANGE=
 SSH_TTY=/dev/pts/0
 USER=root
 LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
 MAIL=/var/spool/mail/root
 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/tmp/:/root/bin
 PWD=/lvm
 LANG=zh_CN.UTF-8
 SELINUX_LEVEL_REQUESTED=
 HISTCONTROL=ignoredups
 SHLVL=1
 HOME=/root
 LOGNAME=root
 XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/
 SSH_CONNECTION=192.168.3.99 63749 192.168.3.136 22
 LESSOPEN=||/usr/bin/lesspipe.sh %s
 XDG_RUNTIME_DIR=/run/user/0
 _=/usr/bin/env
 OLDPWD=/lv
[root@hanlin lvm]# set (显示所有变量,包括自定义的和内置的环境变量)
 自定义变量规则:可以是字母、数字、下划线,首位不能是数字
[root@hanlin lvm]# a='d f g' (有特殊符号的必须要用单引号括起来)
 [root@hanlin lvm]# echo $a
 d f g
 [root@hanlin lvm]# a="abc"    (双引号不区分特殊符号)
 [root@hanlin lvm]# echo $a
 abc
 [root@hanlin lvm]# a='abc'
 [root@hanlin lvm]# echo $a
 abc
 [root@hanlin lvm]# a="a$bc"
 [root@hanlin lvm]# echo $a
 a
 [root@hanlin lvm]# a='a$bc'  (当变量值里面有特殊符号的时候要用单引号括起来,不然识别不了)
 [root@hanlin lvm]# echo $a
 a$bc
  
多个变量值的累加
[root@hanlin lvm]# d=zx$a
 [root@hanlin lvm]# echo $d
 zx1
 [root@hanlin lvm]# d=x'$a' (变量值的累加,有可能混淆的变量用单引号括起来)
 [root@hanlin lvm]# echo $d
 x$a
 全局变量
[root@hanlin ~]# w (查看负载)
 10:26:03 up 4 days, 1:01, 3 users, load average: 0.00, 0.01, 0.05
 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
 root pts/0 192.168.3.99 一09 7:55 10.33s 10.22s -bash
 xy :0 :0 二13 ?xdm? 1:02m 1.32s /usr/libexec/gnome-session-binary -
 root pts/1 192.168.3.99 10:25 3.00s 0.13s 0.02s w
 [root@hanlin ~]# echo $SSH_TTY (查看登入本系统的TTY,系统变量都是大写的)
 /dev/pts/1
  
[root@hanlin ~]# a=123
 [root@hanlin ~]# echo $a
 123
 [root@hanlin ~]# bash (新建一个bash,就是子shell)
 [root@hanlin ~]# echo $a (a没有输出,原来定义的变量不是全局变量)
[root@hanlin ~]#pstree  (显示进程树状图)
 systemd─┬─ModemManager───2*[{ModemManager}]
 ├─NetworkManager───2*[{NetworkManager}]
 ├─VGAuthService
 ├─abrt-dbus───2*[{abrt-dbus}]
 ├─2*[abrt-watch-log]
 ├─abrtd
 ├─accounts-daemon───2*[{accounts-daemon}]
 ├─alsactl
 ├─at-spi-bus-laun─┬─dbus-daemon───{dbus-daemon}
 │ └─3*[{at-spi-bus-laun}]
 ├─at-spi2-registr───2*[{at-spi2-registr}]
 ├─atd
 ├─auditd─┬─audispd─┬─sedispatch
 │ │ └─{audispd}
 │ └─{auditd}
 ├─avahi-daemon───avahi-daemon
 ├─chronyd
 ├─colord───2*[{colord}]
 ├─crond
 ├─cupsd
 ├─2*[dbus-daemon───{dbus-daemon}]
 ├─dbus-launch
 ├─dconf-service───2*[{dconf-service}]
 ├─dnsmasq───dnsmasq
 ├─evolution-addre─┬─evolution-addre───5*[{evolution-addre}]
 │ └─5*[{evolution-addre}]
 ├─evolution-calen─┬─evolution-calen───5*[{evolution-calen}]
 │ ├─evolution-calen───7*[{evolution-calen}]
 │ └─5*[{evolution-calen}]
 ├─evolution-sourc───4*[{evolution-sourc}]
 ├─firewalld───{firewalld}
 ├─gdm─┬─X───5*[{X}]
 │ ├─gdm-session-wor─┬─gnome-session-b─┬─abrt-applet───2*[{abrt-applet}]
 │ │ │ ├─gnome-settings-───4*[{gnome-settings-}]
 │ │ │ ├─gnome-shell─┬─ibus-daemon─┬─ibus-dconf───3*[{ib+
 │ │ │ │ │ ├─ibus-engine-sim───2+
 │ │ │ │ │ └─2*[{ibus-daemon}]
 │ │ │ │ └─14*[{gnome-shell}]
 │ │ │ ├─gnome-software───3*[{gnome-software}]
 │ │ │ ├─nautilus-deskto───3*[{nautilus-deskto}]
 │ │ │ ├─seapplet
 │ │ │ ├─ssh-agent
 │ │ │ ├─tracker-extract───13*[{tracker-extract}]
 │ │ │ ├─tracker-miner-a───3*[{tracker-miner-a}]
 │ │ │ ├─tracker-miner-f───3*[{tracker-miner-f}]
 │ │ │ ├─tracker-miner-u───3*[{tracker-miner-u}]
 │ │ │ └─3*[{gnome-session-b}]
 │ │ └─2*[{gdm-session-wor}]
 │ └─3*[{gdm}]
 ├─gnome-keyring-d───3*[{gnome-keyring-d}]
 ├─gnome-shell-cal───6*[{gnome-shell-cal}]
 ├─goa-daemon───4*[{goa-daemon}]
 ├─goa-identity-se───3*[{goa-identity-se}]
 ├─gsd-printer───2*[{gsd-printer}]
 ├─gssproxy───5*[{gssproxy}]
 ├─gvfs-afc-volume───3*[{gvfs-afc-volume}]
 ├─gvfs-goa-volume───2*[{gvfs-goa-volume}]
 ├─gvfs-gphoto2-vo───2*[{gvfs-gphoto2-vo}]
 ├─gvfs-mtp-volume───2*[{gvfs-mtp-volume}]
 ├─gvfs-udisks2-vo───2*[{gvfs-udisks2-vo}]
 ├─gvfsd───2*[{gvfsd}]
 ├─gvfsd-fuse───5*[{gvfsd-fuse}]
 ├─gvfsd-trash───2*[{gvfsd-trash}]
 ├─ibus-x11───2*[{ibus-x11}]
 ├─irqbalance
 ├─ksmtuned───sleep
 ├─libvirtd───15*[{libvirtd}]
 ├─lsmd
 ├─lvmetad
 ├─master─┬─pickup
 │ └─qmgr
 ├─mcelog
 ├─mission-control───3*[{mission-control}]
 ├─packagekitd───2*[{packagekitd}]
 ├─polkitd───5*[{polkitd}]
 ├─pulseaudio───2*[{pulseaudio}]
 ├─rngd
 ├─rsyslogd───2*[{rsyslogd}]
 ├─rtkit-daemon───2*[{rtkit-daemon}]
 ├─smartd
 ├─sshd───sshd───bash──bash(当前bash)───pstree
├─systemd-journal
 ├─systemd-logind
 ├─systemd-udevd
 ├─tracker-store───7*[{tracker-store}]
 ├─tuned───4*[{tuned}]
 ├─udisksd───4*[{udisksd}]
 ├─upowerd───2*[{upowerd}]
 ├─vmtoolsd───{vmtoolsd}
 ├─vmtoolsd
 ├─wpa_supplicant
 └─xdg-permission-───2*[{xdg-permission-}]
 [root@hanlin ~]# exit (退出当前bash,返回上一层bash)
 exit
 [root@hanlin ~]#export a=123 (定义a的全局变量,只能往下全局识别,往上识别不了,换个bash或者中断登入也识别不了)
[root@hanlin ~]# bash (打开子shell)
[root@hanlin ~]# echo $a
123
[root@hanlin ~]# unset a (取消变量)
[root@hanlin ~]# echo $a
环境变量配置文件
 [root@hanlin ~]# cat /etc/profile (用户环境变量,系统登入的时候才会执行,比如打开终端,登入账号等等会调用profile,然后profile又会自动的调用bashrc
 [root@hanlin ~]# cat /etc/bashrc   (执行shell就生效,不需要登入,只要执行脚本就会调用bashrc)
 
用户家目录下的环境变量 (只在当前用户下执行才有用,想要用于全局,修改/etc/profile)
[root@hanlin ~]# cat /root/.
 ./        .bash_history            .bashrc              .cshrc                .pki/              .viminfo
 ../             .bash_logout              .cache/                .dbus/                    .ssh/         .xauthNNIrHz
 .a.txt.swp         .bash_profile     .config/               .lesshst        .tcshrc                 .xauthttaMMI
  
.bash_logout 如果想要在用户退出的时候做某些命令,把这些命令放入bash_out中就可以了
PS1
[root@hanlin ~]# vim /etc/bashrc 
 [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "    这是bashrc里面默认的PS1配置,表示用户登入进去的界面从左到右依次为[用户-主机名-当前目录]
  
[root@hanlin ~]# echo $PS1
 [\u@\h \W]\$
  
oot@hanlin:~#PS1='[\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\]$' (自定义PS1变量,变换登入的信息颜色)
root@hanlin:~#cd /lvm
 root@hanlin:/lvm#ls
 123 1.ttx 1.txt 1.txt.gzip 2.txt lost+found wc
 root@hanlin:/lvm#cd 123
 root@hanlin:/lvm/123#
 root@hanlin:/lvm/123#echo $PS2
 >
  
特殊符号
* 表示任意所有的字符
? 表示任意一个字符
# 表示注释,命令不生效
\ 脱义字符 表示取消掉字符原来的意思
| 管道符 表示把前面的结果传给后面执行
[root@hanlin:~#]a=1
 [root@hanlin:~#]b=2
 [root@hanlin:~#]c=$a$b
 [root@hanlin:~#]echo $c
 12
 [root@hanlin:~#]c='$a$b'
 [root@hanlin:~#]echo $c
 $a$b
 [root@hanlin:~#]c=\$a\$b
 [root@hanlin:~#]echo $c
 $a$b
来源:oschina
链接:https://my.oschina.net/u/3867255/blog/1838013