当前位置:   article > 正文

#12.Linux中管道_linux从/etc/passwd中抽取1,3,5列,用管道实现

linux从/etc/passwd中抽取1,3,5列,用管道实现

管道

通过管道符"|“,可以把多个简单的命令连接起来实现更加复杂的功能。管道符”|“用于连接左右两个命令,将”|“左边命令的执行结果作为”|“右边命令的输入,这样”|"就像一根管道一样连接着左右两条命令,并在管道中实现数据从左至右的传输。

例如需要对/etc/passwd统计行数,正常的命令是:

[root@localhost ~]# wc -l /etc/passwd
44 /etc/passwd
  • 1
  • 2

而使用管道符的命令

[root@localhost ~]# cat /etc/passwd | wc -l
4
  • 1
  • 2

例如ls命令和more命令可实现目录列表分页显示的功能

[root@localhost ~]# ll -h /etc/passwd | more
  • 1

例如要查找etc目录下以conf结尾的文件个数

[root@localhost ~]# find /etc -name "*.conf" -type f | wc -l
372
  • 1
  • 2

例如从/etc/passwd文件中取出第十行

[root@localhost ~]# head -10 /etc/passwd | tail -1
operator:x:11:0:operator:/root:/sbin/nologin
  • 1
  • 2
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号