linux脚本中怎么退出tee模式,Linux Shell脚本入门:tee命令

用途说明   在执行Linux命令时,我们可以把输出重定向到文件中,比如 ls

>a.txt,这时我们就不能看到输出了,如果我们既想把输出保存到文件中,又想在屏幕上看到输出内容,就可以使用tee命令了。tee命令读取标准输入,把这些内容同时输出到标准输出和(多个)文件中(read

from standard input and write to standard output and files. Copy standard input

to each FILE, and also to standard output. If a FILE is -, copy again to

standard output.)。在info tee中说道:tee命令可以重定向标准输出到多个文件(`tee': Redirect output to

multiple files. The `tee' command copies standard input to standard output and

also to any files given as arguments.  This is useful when you want not only to

send some data down a pipe, but also to save a

copy.)。要注意的是:在使用管道线时,前一个命令的标准错误输出不会被tee读取。

常用参数

格式:tee

只输出到标准输出,因为没有指定文件嘛。

格式:tee

file

输出到标准输出的同时,保存到文件file中。如果文件不存在,则创建;如果已经存在,则覆盖之。(If a file being

written to does not already exist, it is created. If a file being written to

already exists, the data it previously

contained is overwritten unless the

`-a' option is used.)

格式:tee -a file

输出到标准输出的同时,追加到文件file中。如果文件不存在,则创建;如果已经存在,就在末尾追加内容,而不是覆盖。

格式:tee -

输出到标准输出两次。(A FILE of `-' causes `tee' to send another

copy of input to standard output, but this is typically not that useful as the

copies are interleaved.)

格式:tee file1 file2

-

输出到标准输出两次,同时保存到file1和file2中。

使用示例

示例一

tee命令与重定向的对比   [root@web ~]# seq 5 >1.txt

[root@web ~]#

cat 1.txt

1

2

3

4

5

[root@web ~]# cat 1.txt

>2.txt

[root@web ~]# cat 1.txt | tee 3.txt

1

2

3

4

5

[root@web ~]# cat 2.txt

1

2

3

4

5

[root@web ~]# cat 3.txt

1

2

3

4

5

[root@web ~]# cat 1.txt >>2.txt

[root@web ~]# cat 1.txt |

tee -a 3.txt

1

2

3

4

5

[root@web ~]# cat

2.txt

1

2

3

4

5

1

2

3

4

5

[root@web ~]# cat 3.txt

1

2

3

4

5

1

2

3

4

5

[root@web ~]#

示例二 使用tee命令重复输出字符串   [root@web ~]# echo 12345 | tee

12345

[root@web ~]# echo 12345 | tee -

12345

12345

[root@web ~]# echo 12345 | tee - -

12345

12345

12345

[root@web ~]# echo 12345 | tee - - -

12345

12345

12345

12345

[root@web ~]# echo 12345 | tee - - - -

12345

12345

12345

12345

12345

[root@web ~]#

[root@web

~]# echo -n 12345 | tee

12345[root@web ~]# echo -n 12345 | tee -

1234512345[root@web ~]# echo -n 12345 | tee - -

123451234512345[root@web

~]# echo -n 12345 | tee - - -

12345123451234512345[root@web ~]# echo -n

12345 | tee - - - -

1234512345123451234512345[root@web ~]#

示例三 使用tee命令把标准错误输出也保存到文件   [root@web ~]# ls "*"

ls: *: 没有那个文件或目录

[root@web ~]# ls "*" | tee -

ls: *:

没有那个文件或目录

[root@web ~]# ls "*" | tee ls.txt

ls: *: 没有那个文件或目录

[root@web ~]# cat ls.txt

[root@web ~]# ls "*" 2>&1 | tee ls.txt

ls: *: 没有那个文件或目录

[root@web ~]# cat ls.txt

ls: *:

没有那个文件或目录

示例四 列出文本内容,同时复制3份复本

列出文本文件slayers.story的内容,同时复制3份副本,文件名称分别为ss-copy1、ss-copy2、ss-copy3:

[root@web ~]#  cat slayers.story |tee ss-copy1 ss-copy2 ss-copy3

Linux Shell脚本入门--cut命令

Linux Shell脚本入门--cut命令 cut cut 命令可以从一个文本文件或者文本流中提取文本列. cut语法 [root@www ~]# cut -d'分隔字符' -f fields &l ...

Linux Shell脚本入门--wget 命令用法详解

Linux Shell脚本入门--wget 命令用法详解 wget是在Linux下开发的开放源代码的软件,作者是Hrvoje Niksic,后来被移植到包括Windows在内的各个平台上.它有以下功能 ...

Linux Shell 脚本入门

linux shell 脚本格式 #!/bin/sh#..... (注释)命令...命令... 使用vi 创建完成之后需设置权限 chmod +x filename.sh 执行命令: ./filena ...

Linux shell 脚本入门教程+实例

原文:http://www.wiquan.com/article/136 为什么要进行shell编程 在Linux系统中,虽然有各种各样的图形化接口工具,但是shell仍然是一个非常灵活的工具.She ...

Linux Shell脚本入门--awk命令详解

简单使用: awk :对于文件中一行行的独处来执行操作 . awk -F :'{print $1,$4}'   :使用‘:’来分割这一行,把这一行的第一第四个域打印出来 . 详细介绍: AWK命令介绍 ...

Linux Shell脚本入门--grep命令详解

grep简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达 ...

Linux Shell脚本入门--Uniq命令

uniq uniq命令可以去除排序过的文件中的重复行,因此uniq经常和sort合用.也就是说,为了使uniq起作用,所有的重复行必须是相邻的. uniq语法 [root@www ~]# uniq [ ...

Linux Shell脚本入门--wc命令

wc 统计文件里面有多少单词,多少行,多少字符. wc语法 [root@www ~]# wc [-lwm] 选项与参数: -l :仅列出行: -w :仅列出多少字(英文单字): -m :多少字符: 默 ...

随机推荐

mssql数据库添加,修改,删除字段

通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 增加字段: alter table [表名] add 字段名 smalli ...

[CentOS] 指定命令别名:Alias & 软链接生成命令 ln -s

参考:CentOS里alias命令详解 每天一个linux命令(35):ln 命令 1. Alias命令 功能描述:我们在进行系统的管理工作一定会有一些我们经常固定使用,但又很长的命令.那我们可以给这 ...

python学习——将while循环改成函数

笨办法学python第33节 这一节主要学习内容是while循环,记录内容为将while改成函数,首先源代码如下: i = 0 numbers = [] while i < 6: print & ...

Sql服务定时重启

net stop sqlserveragentnet stop mssqlservernet start mssqlservernet start sqlserveragent 保存到记事本中,重命名 ...

用muduo实现memcached协议的例子

最近花了两天时间用 muduo 部分实现了 memcached 服务器协议,代码位于 examples/memcached/server,能通过 memcached 的大部分测试用例(incr/dec ...

Cocos2d-x数据持久化-查询数据

数据查询一般会带有查询条件,这可以使用SQL语句的where子句实现,但是在程序中需要动态绑定参数给where子句.查询数据的具体操作步骤如下所示.(1) 使用sqlite3_open函数打开数据库. ...

centos6&period;8安装cdh5&period;10&period;0(离线版)

Centos6.8安装CDH5 相关包的下载地址: Cloudera Manager地址:http://archive.cloudera.com/cm5/cm/5/ CDH安装包地址:http://a ...

python之路--FTP 上传视频示例

# 服务端 import json import socket import struct server = socket.socket() server.bind(('127.0.0.1',8001 ...

我永远无法学会的dp

起源:在codeforceround518之后我发现别人都会div1A我根本写不出来,所以我决定退役 咕咕咕咕

VOIP NAT穿越之SIP信令穿越

本文原创自 http://blog.csdn.net/voipmaker  转载注明出处. 本文是VOIP通信NAT系列专题的第三篇, 本文论述NAT对SIP协议穿越的影响.SIP协议是基于文本的,而 ...

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值