04_03_Linux

管道和重定向
运算器,控制器:CPU
存储设备:ram
输入输出设备:
程序:

系统设定:
默认输出设备:标准输出 1
默认输入设备:标准输入 0
标准错误输出:STDERR  2

I/O设备重定向
linux:
输出重定向:> (原有内容会被覆盖) ;>>(追加输出)
[root@localhost /]# ls /var > /tmp/var.out
[root@localhost /]# cat /tmp/var.out 
account
cache
crash
db
empty

错误信息是没有重定向的
[root@localhost /]# ls /etcc > /tmp/errtest.out
ls: cannot access /etcc: No such file or directory

重定向错误输出2>
[root@localhost /]# ls /etcc 2> /tmp/errtest.out
[root@localhost /]# cat !$
cat /tmp/errtest.out
ls: cannot access /etcc: No such file or directory
[root@localhost /]# cat << END
> the first line.
> the second line.
> END
the first line.
the second line.


重定向所有的输出:&>


输入重定向:<
[root@localhost /]# cat
sdfg^C
[root@localhost /]# cat < /tmp/errtest.out 
ls: cannot access /etcc: No such file or directory
[root@localhost /]# tr 'a-z' 'A-Z'
ASFDdsf
ASFDDSF
[root@localhost /]# tr 'a-z' 'A-Z' < /tmp/errtest.out
LS: CANNOT ACCESS /ETCC: NO SUCH FILE OR DIRECTORY


此处文档:<<
[root@localhost /]# cat << END
> the first line.
> the second line.
> END
the first line.
the second line.

[root@localhost /]# cat >> /tmp/test.out  <<EOF
> the first line.
> the second line.
> EOF
[root@localhost /]# cat /tmp/test.out 
the first line.
the second line.




set -C:禁止对已经存在的文件进行覆盖(如果要覆盖使用>|)
set +C:关闭上面功能





管道


前一个命令的输出,作为后一个命令的输入
命令1 | 命令2 | 命令3
把echo的输出,作为tr的输入
[root@localhost /]# echo "hello,world" | tr 'a-z' 'A-Z'
HELLO,WORLD

tee:及输出到标准输出有保存文件
[root@localhost /]# echo "hello world." | tee /tmp/hello.out
hello world.
[root@localhost /]# cat tmp/hello.out 
hello world.

只显示一个文件的行数:
[root@localhost /]# wc -l /etc/passwd
41 /etc/passwd
[root@localhost /]# wc -l /etc/passwd | cut -d' ' -f1
41















评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值