Linux中的管道符

一 多命令顺序执行


 
 
二 实战
[root@localhost local]# date;ls;cd /etc;pwd
Sat Jul 15 16:42:39 CST 2017
access.log cs.log etc go jdk1.8.0_111 lib libexec share test2.log test.log
bin error.log games include jdk-8u111-linux-x64.tar.gz lib64 sbin src test3.log
/etc
[root@localhost etc]# date;find /tmp/abc;date
Sat Jul 15 16:48:01 CST 2017
/tmp/abc
Sat Jul 15 16:48:01 CST 2017
[root@localhost etc]# cd ~
[root@localhost ~]# ls && echo yes
anaconda-ks.cfg Documents gobin goproject japan Pictures test
ChangeLog-2.6.0 Downloads goc2p hello.shell linux-2.6.39.tar.bz2 Public Videos
Desktop go1.8.3.linux-amd64.tar.gz golib initial-setup-ks.cfg Music Templates
yes
[root@localhost ~]# lsfdf && echo yes
bash: lsfdf: command not found...
root@localhost ~]# lsfdf || echo yes
bash: lsfdf: command not found...
yes
[root@localhost ~]# ls || echo yes
anaconda-ks.cfg Documents gobin goproject japan Pictures test
ChangeLog-2.6.0 Downloads goc2p hello.shell linux-2.6.39.tar.bz2 Public Videos
Desktop go1.8.3.linux-amd64.tar.gz golib initial-setup-ks.cfg Music Templates
[root@localhost ~]# ls && echo yes || echo no
anaconda-ks.cfg Documents gobin goproject japan Pictures test
ChangeLog-2.6.0 Downloads goc2p hello.shell linux-2.6.39.tar.bz2 Public Videos
Desktop go1.8.3.linux-amd64.tar.gz golib initial-setup-ks.cfg Music Templates
yes
[root@localhost ~]# lsre && echo yes || echo no
bash: lsre: command not found...
no
 
三 管道符
命令格式:
命令1|命令2
命令1的正确输出作为命令2的操作对象
 
四 实战
[root@localhost ~]# ls -l|more
total 89304
-rw-------. 1 root root 1579 Oct 26 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 12777 Dec 18 2003 ChangeLog-2.6.0
drwxr-xr-x. 2 root root 6 Oct 28 2016 Desktop
drwxr-xr-x. 2 root root 6 Oct 28 2016 Documents
drwxr-xr-x. 2 root root 6 Oct 28 2016 Downloads
-rw-r--r--. 1 root root 90029041 Jul 8 15:13 go1.8.3.linux-amd64.tar.gz
drwxr-xr-x. 2 root root 15 Jul 8 19:26 gobin
drwxr-xr-x. 6 root root 4096 Jul 8 18:11 goc2p
drwxr-xr-x. 4 root root 26 Jul 8 19:46 golib
drwxr-xr-x. 2 root root 6 Jul 8 18:10 goproject
-rwxr-xr-x. 1 root root 79 Jul 15 14:39 hello.shell
-rw-------. 1 root root 1627 Oct 26 2016 initial-setup-ks.cfg
drwxr-xr-x. 4 root root 29 Jul 11 21:16 japan
-rw-r--r--. 1 root root 1383989 Nov 12 2016 linux-2.6.39.tar.bz2
drwxr-xr-x. 2 root root 6 Oct 28 2016 Music
drwxr-xr-x. 2 root root 6 Oct 28 2016 Pictures
drwxr-xr-x. 2 root root 6 Oct 28 2016 Public
drwxr-xr-x. 2 root root 6 Oct 28 2016 Templates
drwxr-xr-x. 3 root root 57 Jul 15 09:18 test
drwxr-xr-x. 2 root root 6 Oct 28 2016 Videos
[root@localhost ~]# netstat -an | grep ESTABLISHED
tcp 0 0 192.168.0.106:22 192.168.0.101:35342 ESTABLISHED
[root@localhost ~]# netstat -an | grep ESTABLISHED |wc -l
1
 

猜你喜欢

转载自cakin24.iteye.com/blog/2391633