Linux输出重定向

一 标准输入输出


 
 
二 输出重定向


 
 
三 实战
[root@localhost local]# ifconfig > cs.log
[root@localhost local]# cat cs.log
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.106 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::a00:27ff:fe01:3653 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:01:36:53 txqueuelen 1000 (Ethernet)
RX packets 4085 bytes 330891 (323.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2503 bytes 427391 (417.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 4 bytes 344 (344.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 344 (344.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:1b:2a:d5 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 
[root@localhost local]#
[root@localhost local]# ls
bin cs.log etc games go include jdk1.8.0_111 jdk-8u111-linux-x64.tar.gz lib lib64 libexec sbin share src
[root@localhost local]# ls > cs.log
[root@localhost local]# cat cs.log
bin
cs.log
etc
games
go
include
jdk1.8.0_111
jdk-8u111-linux-x64.tar.gz
lib
lib64
libexec
sbin
share
src
[root@localhost local]# ls >> cs.log
[root@localhost local]# cat cs.log
bin
cs.log
etc
games
go
include
jdk1.8.0_111
jdk-8u111-linux-x64.tar.gz
lib
lib64
libexec
sbin
share
src
bin
cs.log
etc
games
go
include
jdk1.8.0_111
jdk-8u111-linux-x64.tar.gz
lib
lib64
libexec
sbin
share
src
[root@localhost local]# datac 2>test.log
[root@localhost local]# cat test.log
bash: datac: command not found...
[root@localhost local]# datac 2 > test.log
bash: datac: command not found...
 
四 正确输出和错误输出同时保存


 
 
五 实战
[root@localhost local]# date >test2.log 2>&1
[root@localhost local]# cat test2.log
Sat Jul 15 16:05:00 CST 2017
[root@localhost local]# datetime >test2.log 2>&1
[root@localhost local]# cat test2.log
bash: datetime: command not found...
[root@localhost local]# date &>>test3.log
[root@localhost local]# cat test3.log
Sat Jul 15 16:07:01 CST 2017
[root@localhost local]# datetime &>>test3.log
[root@localhost local]# cat test3.log
Sat Jul 15 16:07:01 CST 2017
bash: datetime: command not found...
[root@localhost local]# ls &>/dev/null
[root@localhost local]# cat xdy>>access.log 2>>error.log
[root@localhost local]# cat error.log
cat: xdy: No such file or directory
[root@localhost local]# cat test3.log>>access.log 2>>error.log
[root@localhost local]# cat access.log
Sat Jul 15 16:07:01 CST 2017
bash: datetime: command not found...
 
六 wc命令
wc [选项] [文件名]
选项:
-c:统计字节数
-w:统计单词数
-l:统计行数
 
七 输入重定向
命令<把文件作为命令的输入
命令<<标识符
...
标识符
把两个标识符之间的内容作为输入
 
八 实战
[root@localhost local]# wc
rere
tr
uyu yt
tyty
 
5 5 21
[root@localhost local]# wc < access.log
2 11 66
[root@localhost local]# wc access.log
2 11 66 access.log
[root@localhost local]# wc << ddy
> erwr
> erwtrt trer
> werertrt tre
> rertr
> ddy
4 6 36
 
  • 大小: 154.8 KB
  • 大小: 183.3 KB
  • 大小: 173.1 KB
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值