Linux——tee命令终端输出到文件

本文详细介绍了Linux命令`tee`的基本用法,包括如何将命令输出同时显示在终端和写入文件,以及如何追加内容到已有文件。通过实例展示了`tee -a`选项的使用,并提供了`tee --help`的命令帮助信息,帮助读者理解并熟练运用`tee`进行数据重定向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

常用tee命令

command|tee filecommand输出在终端的同时输出到文件file中
command|tee file1 file2command输出到终端的同时输出到文件file1file2
command|tee -a filecommand输出到终端的同时追加到文件file

tee命令实战

$ ll
total 0
-rw-r--r-- 1 root root 0 Dec 31 09:19 base1.txt
-rw-r--r-- 1 root root 0 Dec 31 09:19 base2.txt
-rw-r--r-- 1 root root 0 Dec 31 09:19 base3.txt
$ ll | tee ll.txt
$ cat -n ll.txt     
1  total 0     
2  -rw-r--r-- 1 root root 0 Dec 31 09:19 base1.txt     
3  -rw-r--r-- 1 root root 0 Dec 31 09:19 base2.txt     
4  -rw-r--r-- 1 root root 0 Dec 31 09:19 base3.txt
$ ll | tee ll1.txt ll2.txt同时输出到两个文件中
$ ll | tee -a ll.txt追加到文件中

tee --help

$ tee --help
Usage: tee [OPTION]... [FILE]...
Copy standard input to each FILE, and also to standard output.

  -a, --append              append to the given FILEs, do not overwrite
  -i, --ignore-interrupts   ignore interrupt signals
  -p                        diagnose errors writing to non pipes
      --output-error[=MODE]   set behavior on write error.  See MODE below
      --help     display this help and exit
      --version  output version information and 
exit

tee GNU解释

https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html#tee-invocation
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值