管道
通过管道符"|“,可以把多个简单的命令连接起来实现更加复杂的功能。管道符”|“用于连接左右两个命令,将”|“左边命令的执行结果作为”|“右边命令的输入,这样”|"就像一根管道一样连接着左右两条命令,并在管道中实现数据从左至右的传输。
例如需要对/etc/passwd统计行数,正常的命令是:
[root@localhost ~]# wc -l /etc/passwd
44 /etc/passwd
而使用管道符的命令
[root@localhost ~]# cat /etc/passwd | wc -l
4
例如ls命令和more命令可实现目录列表分页显示的功能
[root@localhost ~]# ll -h /etc/passwd | more
例如要查找etc目录下以conf结尾的文件个数
[root@localhost ~]# find /etc -name "*.conf" -type f | wc -l
372
例如从/etc/passwd文件中取出第十行
[root@localhost ~]# head -10 /etc/passwd | tail -1
operator:x:11:0:operator:/root:/sbin/nologin