Linux学习之shell 编程基础(四)

一、数据流重导向

Linux学习之shell 编程基础(四)_第1张图片 指令执行过程的数据传输情况

(1) 标准输出(stdout):代码为1,使用> 或 >> 

  • 1> :以覆盖的方法将正确的数据输出到指定的文件,其中1可以省略;
[dalianmao@localhost ~]$ ll ~
total 60
-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
-rw-rw-r--. 1 dalianmao dalianmao  928 Nov  5 00:06 homefile
-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc
[dalianmao@localhost ~]$ ll ~ 1> ~/homefile 
[dalianmao@localhost ~]$ nl homefile 
     1	total 56
     2	-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
     3	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
     4	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
     5	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
     6	-rw-rw-r--. 1 dalianmao dalianmao    0 Nov  5 00:09 homefile
     7	-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
     8	-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
     9	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
    10	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
    11	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
    12	-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
    13	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
    14	-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
    15	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
    16	drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc
[dalianmao@localhost ~]$ ll ~ > ~/homefile 
[dalianmao@localhost ~]$ nl homefile 
     1	total 56
     2	-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
     3	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
     4	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
     5	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
     6	-rw-rw-r--. 1 dalianmao dalianmao    0 Nov  5 00:10 homefile
     7	-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
     8	-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
     9	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
    10	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
    11	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
    12	-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
    13	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
    14	-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
    15	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
    16	drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc
  • 1>>:以累加的方法将正确的数据输出到指定的文件上,其中1可以省略;
[dalianmao@localhost ~]$ ll ~ >> ~/homefile 
[dalianmao@localhost ~]$ nl homefile 
     1	total 56
     2	-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
     3	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
     4	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
     5	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
     6	-rw-rw-r--. 1 dalianmao dalianmao    0 Nov  5 00:10 homefile
     7	-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
     8	-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
     9	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
    10	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
    11	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
    12	-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
    13	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
    14	-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
    15	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
    16	drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc
    17	total 60
    18	-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
    19	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
    20	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
    21	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
    22	-rw-rw-r--. 1 dalianmao dalianmao  928 Nov  5 00:10 homefile
    23	-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
    24	-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
    25	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
    26	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
    27	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
    28	-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
    29	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
    30	-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
    31	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
    32	drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc
[dalianmao@localhost ~]$ ll ~ 1>> ~/homefile 
[dalianmao@localhost ~]$ nl homefile 
     1	total 56
     2	-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
     3	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
     4	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
     5	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
     6	-rw-rw-r--. 1 dalianmao dalianmao    0 Nov  5 00:10 homefile
     7	-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
     8	-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
     9	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
    10	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
    11	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
    12	-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
    13	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
    14	-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
    15	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
    16	drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc
    17	total 60
    18	-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
    19	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
    20	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
    21	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
    22	-rw-rw-r--. 1 dalianmao dalianmao  928 Nov  5 00:10 homefile
    23	-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
    24	-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
    25	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
    26	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
    27	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
    28	-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
    29	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
    30	-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
    31	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
    32	drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc
    33	total 60
    34	-rw-rw-r--. 1 dalianmao dalianmao   27 Nov  4 23:17 catfile
    35	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Desktop
    36	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Documents
    37	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Downloads
    38	-rw-rw-r--. 1 dalianmao dalianmao 1856 Nov  5 00:13 homefile
    39	-rw-rw-r--. 1 dalianmao dalianmao   36 Oct 18 04:01 list_error
    40	-rw-rw-r--. 1 dalianmao dalianmao    9 Oct 18 04:01 list_right
    41	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Music
    42	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Pictures
    43	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Public
    44	-rw-rw-r--. 1 dalianmao dalianmao  665 Oct 21 04:07 regular_express.txt
    45	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Templates
    46	-rw-rw-r--. 1 dalianmao dalianmao  125 Sep 30 23:23 test.txt
    47	drwxr-xr-x. 2 dalianmao dalianmao 4096 Jul 11 08:01 Videos
    48	drwxr-xr-x. 3 root      root      4096 Sep 21 09:13 wzc

(2)标准错误输出(stderr):代码为2,使用2> 或者2>>;

  • 2>:以覆盖的方法将错误的数据输出到指定的文件上;
[dalianmao@localhost /]$ cd /root
-bash: cd: /root: Permission denied
[dalianmao@localhost /]$ cd /root 2> ~/rootfile
[dalianmao@localhost /]$ cat ~/rootfile 
-bash: cd: /root: Permission denied
[dalianmao@localhost /]$ cd /root 2> ~/rootfile
[dalianmao@localhost /]$ cat ~/rootfile 
-bash: cd: /root: Permission denied
  • 2>>:以累加的方法将错误的数据输出到指定的文件上;
[dalianmao@localhost /]$ cd /root 2>> ~/rootfile
[dalianmao@localhost /]$ nl ~/rootfile 
     1	-bash: cd: /root: Permission denied
     2	-bash: cd: /root: Permission denied
[dalianmao@localhost /]$ cd /root 2>> ~/rootfile
[dalianmao@localhost /]$ nl ~/rootfile 
     1	-bash: cd: /root: Permission denied
     2	-bash: cd: /root: Permission denied
     3	-bash: cd: /root: Permission denied
  • 2>&1:以覆盖的方法将正确与错误的数据通通写入同一个文件

(2)标准输入(standard input):<与<<;

将原本需要由键盘输入的数据,改由文件内容来取代

eg1.键盘输入

[dalianmao@localhost ~]$ cat > catfile
hahaha^H^H^H
tetst
dalaim^H^H^Hmm
dalianmao[dalianmao@localhost ~]$ nl catfile
     1	hahaha
     2	tetst
     3	dalmmm
     4	dalianmao

eg2. 改用文件取代键盘输入,如将 ~/.bashrc文件内容写进catfile

[dalianmao@localhost ~]$ cat > catfile < ~/.bashrc
[dalianmao@localhost ~]$ ll catfile  ~/.bashrc
-rw-rw-r--. 1 dalianmao dalianmao 124 Nov  5 00:37 catfile
-rw-r--r--. 1 dalianmao dalianmao 124 Jul 18  2013 /home/dalianmao/.bashrc

eg3.<< 表示结束输入字符,如下面的dalianmao就是在下设定的结束字符,没有这个,就得用ctrl+d结束输入了。

[dalianmao@localhost ~]$ cat > catfile <<'dalianmao'
> hahaha
> test
> 12345
> dalianmao
[dalianmao@localhost ~]$ nl catfile
     1	hahaha
     2	test
     3	12345

二、指令执行的判断依据

指令下达情况 说明
cmd1;cmd2 cmd1执行完后接着立刻执行cmd2
cmd1&&cmd2

1.若cmd1 执行完毕且正确执行($?=0),则开始执行cmd2。

2.若cmd1 执行完毕且为错误($?<>0),则cmd2不执行。

cmd1 || cmd2

1.若cmd1执行完毕且正确执行($?=0),则cmd2不执行。

2.若cmd1执行完毕且为错误($?<>0),则开始执行cmd2。


 

 

 

 

 

1)管线命令:|

Linux学习之shell 编程基础(四)_第2张图片 管线命令处理示意图

 

2)选取命令:cut、grep

1、cut       

-d :后面接分隔字符,与-f一起使用

-f:依据-d的分隔字符将一段讯息分割成为数段,用 -f取出第几段的意思。

-c:以字符(characters)的单位取出固定字符区间。

eg1.将PATH变量取出,找出第1个变量

[dalianmao@localhost ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/dalianmao/bin
[dalianmao@localhost ~]$ echo $PATH|cut -d ':' -f 1
/usr/local/bin

eg2.将PATH变量取出,找出第1个和7个变量

[dalianmao@localhost ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/dalianmao/bin
[dalianmao@localhost ~]$ echo $PATH|cut -d ':' -f 1,7
/usr/local/bin:/home/dalianmao/bin

eg3.将export输出的信息,取第12个字符以后的所有字符

[dalianmao@localhost ~]$ export
declare -x G_BROKEN_FILENAMES="1"
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
declare -x HOME="/home/dalianmao"
declare -x HOSTNAME="localhost.localdomain"
declare -x LANG="en_US.UTF-8"
declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
declare -x LOGNAME="dalianmao"
declare -x 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:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=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:*.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:"
declare -x MAIL="/var/spool/mail/dalianmao"
declare -x OLDPWD="/"
declare -x PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/dalianmao/bin"
declare -x PWD="/home/dalianmao"
declare -x SELINUX_LEVEL_REQUESTED=""
declare -x SELINUX_ROLE_REQUESTED=""
declare -x SELINUX_USE_CURRENT_RANGE=""
declare -x SHELL="/bin/bash"
declare -x SHLVL="1"
declare -x SSH_ASKPASS="/usr/libexec/openssh/gnome-ssh-askpass"
declare -x SSH_CLIENT="192.168.235.1 53740 22"
declare -x SSH_CONNECTION="192.168.235.1 53740 192.168.235.129 22"
declare -x SSH_TTY="/dev/pts/0"
declare -x TERM="xterm"
declare -x USER="dalianmao"
[dalianmao@localhost ~]$ export |cut -c 12-
G_BROKEN_FILENAMES="1"
HISTCONTROL="ignoredups"
HISTSIZE="1000"
HOME="/home/dalianmao"
HOSTNAME="localhost.localdomain"
LANG="en_US.UTF-8"
LESSOPEN="||/usr/bin/lesspipe.sh %s"
LOGNAME="dalianmao"
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:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=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:*.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/dalianmao"
OLDPWD="/"
PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/dalianmao/bin"
PWD="/home/dalianmao"
SELINUX_LEVEL_REQUESTED=""
SELINUX_ROLE_REQUESTED=""
SELINUX_USE_CURRENT_RANGE=""
SHELL="/bin/bash"
SHLVL="1"
SSH_ASKPASS="/usr/libexec/openssh/gnome-ssh-askpass"
SSH_CLIENT="192.168.235.1 53740 22"
SSH_CONNECTION="192.168.235.1 53740 192.168.235.129 22"
SSH_TTY="/dev/pts/0"
TERM="xterm"
USER="dalianmao"

2、grep

-a:将binary档案以text档案的方式搜寻数据

-c:计算找到 '待搜寻字符串' 的次数

-i :忽略大小写的不同

-n :顺便输出行号

-v :反向选择

3)排序命令:sort、wc、uniq

sort、uniq这里不罗嗦了,用到的时候自己查查吧。

重点wc:

-l:仅列出行;

-w:仅列出多少字(英文单字)

-m:多少字符;

[dalianmao@localhost ~]$ cat /etc/man.config|wc
    152     765    4940
[dalianmao@localhost ~]$ cat /etc/man.config|wc -l
152
[dalianmao@localhost ~]$ cat /etc/man.config|wc -w
765
[dalianmao@localhost ~]$ cat /etc/man.config|wc -m
4940
[dalianmao@localhost ~]$ 

 

你可能感兴趣的:(Linux学习之shell 编程基础(四))