欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux输出重定向

程序员文章站 2022-04-17 23:18:40
...
一 标准输入输出

Linux输出重定向
            
    
    博客分类: Linux Linux重定向 
 
 
二 输出重定向

Linux输出重定向
            
    
    博客分类: Linux 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...
 
四 正确输出和错误输出同时保存

Linux输出重定向
            
    
    博客分类: Linux Linux重定向 
 
 
五 实战
[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
 
  • Linux输出重定向
            
    
    博客分类: Linux Linux重定向 
  • 大小: 154.8 KB
  • Linux输出重定向
            
    
    博客分类: Linux Linux重定向 
  • 大小: 183.3 KB
  • Linux输出重定向
            
    
    博客分类: Linux Linux重定向 
  • 大小: 173.1 KB
相关标签: Linux 重定向