Aliases and redirects input, output and variables

Table of Contents

Nick name

Select Alias:

Alias ​​NAME = “commond”

[[email protected] ~]# alias net ="vi /etc/sysconfig/network-scripts/ifcfg-eth0"

Eliminate Alias:

[[email protected] ~]# unalias net

Skip aliases (: rotary -symbol)

[[email protected] ~]# \net

Let aliases take effect permanently:

[[email protected] ~]# vi /etc bashrc

add to the least

"alias net="vi /etc/sysconfig/network-scripts/ifcfg-ens33"" 

[[email protected] ~]# source /etc bashrc

Standard input and output redirection:

standard input: 0; standard output: 1; Error output: 2

File standard output: > file name (cover)

[[email protected]alhost ~]# ls > file1
[[email protected] ~]# cat file1
anaconda-ks.cfg
apr-1.7.0.tar.gz
ceu
dev
err
errlog
file1
httpd-2.4.39
httpd-2.4.39.tar.bz2
null

Output error to file: 2>filename (cover)

[[email protected] ~]# mysql 2>file2
[[email protected] ~]# cat file2
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Output standard to file file, error output on Errname: > FileName 2 > Errname

[[email protected] ~]# ll anaconda-ks.cfg anaconda-ks1.cfg  >file3 2>file4
[[email protected] ~]# cat file3
-rw-------. 1 root root 1532 Jul 22 16:14 anaconda-ks.cfg
[[email protected] ~]# cat file4
ls: cannot access anaconda-ks1.cfg: No such file or directory

Input and output correct input and error input to file filename:

[[email protected] ~]# ll anaconda-ks.cfg anaconda-ks1.cfg  &>file5
[[email protected] ~]# cat file5
ls: cannot access anaconda-ks1.cfg: No such file or directory
-rw-------. 1 root root 1532 Jul 22 16:14 anaconda-ks.cfg

Input and output correct input and error input to file filename:

[[email protected] ~]# ll anaconda-ks.cfg anaconda-ks1.cfg  >file6 2>&1
[[email protected] ~]# cat file6
ls: cannot access anaconda-ks1.cfg: No such file or directory
-rw-------. 1 root root 1532 Jul 22 16:14 anaconda-ks.cfg

>, 2>: cover the original content

>>, 2 >>, added to the back of the original content

/dev/null: garbage

Factor

global variable: valid in the current file

Local variable: operates on a line of code or code lock

Environment Variables: This is effective for all processes and child processes within the current shell (Echo $Path prints all environment variables)

Leave a Comment