tee redirect & vim

tee [OPTION]... [FILE]...
     +-----------+    tee     +------------+
     |           |  --------  |            |
     | ps -ax    |  --------  | grep 'foo' |
     |           |     ||     |            |
     +-----------+     ||     +------------+
                       ||   
               +---------------+
               |               |
               | processes.txt |
               |               |
               +---------------+

Options

-a, --append 	Append to the given FILEs. Do not overwrite.
-i, --ignore-interrupts 	Ignore interrupt signals.
--help 	Display a help message, and exit.
--version 	Display version information, and exit.

输出到stdout同时,覆盖写入文件

df -h | tee disk_usage.txt

只写入文件,不输出到stdout

command | tee file.out >/dev/null

sudo 模式将信息追加到指定文件,同时stdout显示

echo "newline" | sudo tee -a /etc/file.conf

重定向同时,写入文件

grep 'root' /etc/passwd | tee /tmp/passwd.tmp | wc -l

同时覆盖写入多个文件

command | tee file1.out file2.out file3.out

追加模式写入

command | tee -a file.out

写入内容忽略中断信号ctrl+c

command | tee -i file.out

vim sudo写入

:w !sudo tee %

You can add this to your .vimrc to make this trick easy-to-use: just type :w!!.

" Allow saving of files as sudo when I forgot to start vim using sudo.

cmap w!! w !sudo tee > /dev/null %

The > /dev/null part explicitly throws away the standard output, since, as I said, we don't need to pass anything to another piped command.

posted @ 2020-10-27 08:48  fndefbwefsowpvqfx  阅读(76)  评论(0编辑  收藏  举报