xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Linux tee command All In One

Linux tee command All In One

tee – duplicate standard input

image

zsh

image

tee

# tee [-ai] [file ...]
$ echo "Hello" | tee greetings.txt

$ man tee

TEE(1)                       General Commands Manual                      TEE(1)

NAME
     tee – duplicate standard input

SYNOPSIS
     tee [-ai] [file ...]

DESCRIPTION
     The tee utility copies standard input to standard output, making a copy in
     zero or more files.  The output is unbuffered.

     The following options are available:

     -a      Append the output to the files rather than overwriting them.

     -i      Ignore the SIGINT signal.

     The following operands are available:

     file    A pathname of an output file.

     The tee utility takes the default action for all signals, except in the
     event of the -i option.

EXIT STATUS
     The tee utility exits 0 on success, and >0 if an error occurs.

EXAMPLES
     Send the echoed message both to stdout and to the greetings.txt file:

           $ echo "Hello" | tee greetings.txt
           Hello

STANDARDS
     The tee utility is expected to be IEEE Std 1003.2 (“POSIX.2”) compatible.

macOS 12.3                        June 23, 2020                       macOS 12.3
➜  shell-demos 

demos

# 把标准输入,同时输出到多个文件中
$ echo "# Hello World" | tee file.md file.txt file.sh

image

# 覆盖
$ echo "# Hello World 1" | tee file.md file.txt file.sh
# 等价于
$ echo "# Hello World 1" | tee > file.md file.txt file.sh

# 追加
$ echo "# Hello World 2" | tee -a file.md file.txt file.sh

image

# 忽略信号量
$ echo "# Hello World 3" | tee -i single.md

2>&1

# 输出到 markdown 文件
$ man tee > man-tee.md 2>&1

$ cat man-tee.md

>/dev/null / &>/dev/null

# 忽略所有输出, 即把标准输出,写入一个不存在的空设备文件  ✅
$ echo "ignore any output" | tee >/dev/null

https://github.com/xgqfrms/linux

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

rm -rf

# 批量删除,同时删除多个文件

# pipeline ❌
$  ls |  grep "file" | rm -f

$  ls |  grep "file"

# * 通配符,批量删除 ✅
$ rm -f file*

https://linuxize.com/post/how-to-remove-files-and-directories-using-linux-command-line/

https://linuxize.com/post/rm-command-in-linux/

https://linuxize.com/post/unlink-command-in-linux/

refs

https://www.runoob.com/linux/linux-comm-tee.html

https://linuxize.com/post/linux-tee-command/

https://linuxize.com/post/bash-write-to-file/



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-11-20 22:07  xgqfrms  阅读(17)  评论(5编辑  收藏  举报