8.6 pipe symbol and job control
pipe: Give the result of the previous command output to the following command | Separated
Cat 1.txt |wc-l; Cat 1.txt |grep ' aaa '
CTRL Z pauses a task
Jobs view the tasks in the background
BG [ID] Transfer tasks to the background
FG [ID] Transfer the task to the foreground
Command back & drop directly into the background
[[email protected] ~] # vim 1.txt
[1] + Stopped vim 1.txt ## ctrl + z Throw the task into the background
[[email protected] ~] # df -h
File System Capacity Used Available Available Used Mount Point
/ dev / sda3 18G 1.9G 16G 11% /
devtmpfs 479M 0 479M 0% / dev
tmpfs 489M 0 489M 0% / dev / shm
tmpfs 489M 6.7M 482M 2% / run
tmpfs 489M 0 489M 0% / sys / fs / cgroup
/ dev / sdb 10G 33M 10G 1% / mnt
/ dev / sda1 197M 97M 100M 50% / boot
tmpfs 98M 0 98M 0% / run / user / 0
[[email protected] ~] # ls
anaconda-ks.cfg
[[email protected] ~] # fg
vim 1.txt
[[email protected] ~] # vim 1.txt
[1] + stopped vim 1.txt
[[email protected] ~] # vim aa.txt
[2] + Stopped vim aa.txt
[[email protected] ~] # jobs
[1]-stopped vim 1.txt
[2] + Stopped vim aa.txt
· Add & after the command and throw it directly to the background
[[email protected] ~] # sleep 1000 &
[3] 1207
[[email protected] ~] # jobs
[1]-stopped vim 1.txt
[2] + Stopped vim aa.txt
[3] Sleep 1000 & running
[[email protected] ~] # fg 3 ## Background command fg to the foreground, ctrl + z pause
sleep 1000
^ Z
[3] + sleep 1000 stopped
[[email protected] ~] # jobs
[1]-stopped vim 1.txt
[2] Stopped vim aa.txt
[3] + sleep 1000 stopped
8.7, 8.8 shell variables
PATH environment variable, HOME, PWD, LOGNAME and other variables
· View variable: env
[[email protected] ~] # env
XDG_SESSION_ID = 1
HOSTNAME = localhost.localdomain
SELINUX_ROLE_REQUESTED =
TERM = xterm
SHELL = / bin / bash
HISTSIZE = 5000
SSH_CLIENT = 192.168.65.1 14053 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 = 0 1; 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: / root / bin
PWD = / root
LANG = zh_CN.UTF-8
SELINUX_LEVEL_REQUESTED =
HISTCONTROL = ignoredups
SHLVL = 1
HOME = / root
LOGNAME = root
SSH_CONNECTION = 192.168.65.1 4134 192.168.65.128 22
LESSOPEN = || /usr/bin/lesspipe.sh% s
XDG_RUNTIME_DIR = / run / user / 0
_ = / usr / bin / env
· View variables: set (not only the system built-in environment variables, but also user-defined variables)
· Custom variable: a = 1
[[email protected] ~] # a = 111
[[email protected] ~] # echo $ a111
[[email protected] ~] # set | grep 111
_ = 111
a = 111
(Custom variables can be found by set, but not by env)
· Variable name rules: letters and numbers are underlined, the first digit cannot be a number
a1 √
a_1 √
_a1 √
1a ×
· Variable values have special symbols that need to be enclosed in single quotes
a = 'a b c'
· The accumulation of variables
[[email protected] ~] # a = 1
[[email protected] ~] # b = 2
[[email protected] ~] # echo $ a $ b
12
[[email protected] ~] # w
20:08:04 up 5 min, 1 user, load average: 0.00, 0.02, 0.02
USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
root pts / 0 192.168.65.1 15:28 6.00s 0.40s 0.03s w
root pts / 1 192.168.65.1 18:13 3.00s 0.04s 0.04s -bash
[[email protected] ~] # echo $ SSH_TTY
/ dev / pts / 0
[[email protected] ~] # bash
[[email protected] ~] # pstree
systemd─┬─NetworkManager───2 * [{NetworkManager}]
├─VGAuthService
├─agetty
├─auditd─── {auditd}
├─chronyd
├─crond
├─dbus-daemon─── {dbus-daemon}
├─firewalld─── {firewalld}
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─polkitd───5 * [{polkitd}]
├─rsyslogd───2 * [{rsyslogd}]
├─sshd─┬─sshd───bash─┬─bash───pstree ## in the child process
│ │ ├─sleep
│ │ └─2 * [vim]
│ └─sshd───bash
├─systemd-journal
├─systemd-logind
├─systemd-udevd
├─tuned───4 * [{tuned}]
└─vmtoolsd
[[email protected] ~] # echo $ a ## In the child process, the variables defined in the previous shell are not recognized
[[email protected] ~] # exit
exit
[[email protected] ~] # pstree
systemd─┬─NetworkManager───2 * [{NetworkManager}]
├─VGAuthService
├─agetty
├─auditd─── {auditd}
├─chronyd
├─crond
├─dbus-daemon─── {dbus-daemon}
├─firewalld─── {firewalld}
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─polkitd───5 * [{polkitd}]
├─rsyslogd───2 * [{rsyslogd}]
├─sshd─┬─sshd───bash─┬─pstree
│ │ ├─sleep
│ │ └─2 * [vim]
│ └─sshd───bash
├─systemd-journal
├─systemd-logind
├─systemd-udevd
├─tuned───4 * [{tuned}]
└─vmtoolsd
[[email protected] ~] # echo $ a
1
So these variables become local variables or non-global variables
· Global variables: export variables = value ## Global variables only take effect in it and its subshells
[[email protected] ~] # export c = 123
[[email protected] ~] # echo $ c
123
[[email protected] ~] # bash
[[email protected] ~] # bash
[[email protected] ~] # pstree
systemd─┬─NetworkManager───2 * [{NetworkManager}]
├─VGAuthService
├─agetty
├─auditd─── {auditd}
├─chronyd
├─crond
├─dbus-daemon─── {dbus-daemon}
├─firewalld─── {firewalld}
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─polkitd───5 * [{polkitd}]
├─rsyslogd───2 * [{rsyslogd}]
├─sshd─┬─sshd───bash─┬─bash───bash───pstree
│ │ ├─sleep
│ │ └─2 * [vim]
│ └─sshd───bash
├─systemd-journal
├─systemd-logind
├─systemd-udevd
├─tuned───4 * [{tuned}]
└─vmtoolsd
[[email protected] ~] # echo $ c
123
[[email protected] ~] # export d = 321
[[email protected] ~] # echo $ d
321
[[email protected] ~] # exit
exit
[[email protected] ~] # pstree
systemd─┬─NetworkManager───2 * [{NetworkManager}]
├─VGAuthService
├─agetty
├─auditd─── {auditd}
├─chronyd
├─crond
├─dbus-daemon─── {dbus-daemon}
├─firewalld─── {firewalld}
├─lvmetad
├─master─┬─pickup
│ └─qmgr
├─polkitd───5 * [{polkitd}]
├─rsyslogd───2 * [{rsyslogd}]
├─sshd─┬─sshd───bash─┬─bash───pstree
│ │ ├─sleep
│ │ └─2 * [vim]
│ └─sshd───bash
├─systemd-journal
├─systemd-logind
├─systemd-udevd
├─tuned───4 * [{tuned}]
└─vmtoolsd
[[email protected] ~] # echo $ d ## Global variables set in the subshell cannot be displayed globally in the upper shell
· Unset variable
[[email protected] ~] # echo $ c
123
[[email protected] ~] # unset c
[[email protected] ~] # echo $ c
8.9 Environment Variable Configuration File
There are two categories of system environment configuration files:
1. Under the system level / etc /
2. User level, under the user's home directory
The difference between profile and bashrc is that profile is loaded and executed when the user logs in, and bashrc is effective when executing shell script
/ etc / profile User environment variables, only after interaction and login
/ etc / bashrc users do not need to log in, execute the shell to take effect
(The above two directories should not be disturbed, usually modify the ones under the home directory)
After the configuration file is modified, you can use the source file or .file to reload
For example: source / etc / profile or. / Etc / profile
~ / .bashrc User command aliases and other personalization
~ / .bash_profile Set environment information for users
~ / .bash_history Store user command history
~ / .bash_logout is used to define some operations that the user needs to do when logging out
Variable PS1 defines the prompt, modify it under / etc / bashrc
[[email protected] ~] # echo $ PS1
[\ [email protected] \ h \ W] \ $ ## If you replace W with w, the path will become an absolute path
[[email protected] ~] # PS1 = '[\ [email protected] \ h \ w] \ $'
[[email protected] ~] #cd / tmp / d6z /
[[email protected] / tmp / d6z] # PS1 = '[\ [email protected] \ h \ W] \ $'
[[email protected] d6z] #
Can be set with color display
PS1 = '\ [\ 033 [01; 32m \] \ [email protected] \ h \ [\ 033 [00m \]: \ [\ 033 [01; 36m \] \ w \ [\ 033 [00m \] \ $ '
2018-1-11 4 lessons in 5 weeks Pipeline character, job control, shell variable, environment variable configuration