博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux - 重定向与管道
阅读量:4583 次
发布时间:2019-06-09

本文共 1770 字,大约阅读时间需要 5 分钟。

标准输出重定向

">" 操作符:覆盖目标文件内容

huey@huey-K42JE:~/huey/linux/cmdline$ date > foohuey@huey-K42JE:~/huey/linux/cmdline$ cat fooFri May 8 09:55:42 CST 2015

">>" 操作符:在目标文件尾部追加输出内容

huey@huey-K42JE:~/huey/linux/cmdline$ date >> foohuey@huey-K42JE:~/huey/linux/cmdline$ cat fooFri May 8 09:55:42 CST 2015Fri May 8 09:57:02 CST 2015

 

标准错误重定向

"2>" 操作符:覆盖目标文件内容

huey@huey-K42JE:~/huey/linux/cmdline$ ls inexistent_dir 2> ls-error.txt huey@huey-K42JE:~/huey/linux/cmdline$ cat ls-error.txt ls: cannot access inexistent_dir: No such file or directory

"2>>" 操作符:在目标文件尾部追加输出内容

huey@huey-K42JE:~/huey/linux/cmdline$ ls inexistent_dir 2>> ls-error.txt huey@huey-K42JE:~/huey/linux/cmdline$ cat ls-error.txt ls: cannot access inexistent_dir: No such file or directoryls: cannot access inexistent_dir: No such file or directory

 

将标准输出与标准错误重定向到同一文件

"&>" 操作符:覆盖目标文件内容

huey@huey-K42JE:~/huey/linux/cmdline$ date &> foohuey@huey-K42JE:~/huey/linux/cmdline$ cat fooFri May 8 10:16:12 CST 2015huey@huey-K42JE:~/huey/linux/cmdline$ ls inexistent_dir &> foo huey@huey-K42JE:~/huey/linux/cmdline$ cat fools: cannot access inexistent_dir: No such file or directory

"&>>" 操作符:在目标文件尾部追加输出内容

huey@huey-K42JE:~/huey/linux/cmdline$ echo 'hello world' > foohuey@huey-K42JE:~/huey/linux/cmdline$ date &>> foohuey@huey-K42JE:~/huey/linux/cmdline$ ls inexistent_dir &>> foo huey@huey-K42JE:~/huey/linux/cmdline$ cat foohello worldFri May 8 10:25:24 CST 2015ls: cannot access inexistent_dir: No such file or directory

 

标准输入重定向

"<" 操作符

huey@huey-K42JE:~/huey/linux/cmdline$ echo 'hello world' > foohuey@huey-K42JE:~/huey/linux/cmdline$ cat < foohello world

 

管道

"|" 操作符

huey@huey-K42JE:~/huey/linux/cmdline$ ls /usr/bin | grep '^zip'zipzipcloakzipgrepzipinfozipnotezipsplit

 

转载于:https://www.cnblogs.com/huey/p/4487021.html

你可能感兴趣的文章
JS实现数组排序:升序和降序
查看>>
怎样写具体设计文档
查看>>
CAShapeLayer
查看>>
ACM_夏天到了,又到了出游的季节
查看>>
【转载】HTTP 错误 500.19 - Internal Server Error
查看>>
2015 Multi-University Training Contest 3 hdu 5325 Crazy Bobo
查看>>
SQL Server 存储图片
查看>>
php特级课---4、网站服务监控(常用网站服务监控软件有哪些)
查看>>
ubuntu14.04 boost 1.58.0 安裝
查看>>
漏洞基本概念
查看>>
直角三角形 (Standard IO)
查看>>
web 12
查看>>
Centos7安装Nginx
查看>>
探讨在线支付平台支付接口的设计
查看>>
【设计模式】常用设计模式总结
查看>>
.NET中的六个重要概念
查看>>
二十九、简谈设计模式
查看>>
js中数组的检测方法
查看>>
[译]GotW #6a: Const-Correctness, Part 1
查看>>
JAVA基础学习之 Map集合、集合框架工具类Collections,Arrays、可变参数、List和Set集合框架什么时候使用等(4)...
查看>>