标签: tee

如何将输出重定向到多个日志文件

如何将标准输出重定向到多个日志文件?以下不起作用:

some_command 1> output_log_1 output_log_2 2>&1
Run Code Online (Sandbox Code Playgroud)

linux io-redirection tee

70
推荐指数
5
解决办法
12万
查看次数

使用 exec 和 tee 同时将日志重定向到 stdout 和日志文件

在 bash 脚本中,如何使用 将所有标准输出重定向到日志文件和tee屏幕上的输出exec

log_file="$HOME/logs/install.txt-`date +'%Y-%m-%d_%H-%M-%S'`"
[ -f "$log_file" ] || touch "$log_file"
exec 1>> $log_file 2>&1
Run Code Online (Sandbox Code Playgroud)

此代码将所有日志重定向到日志文件而不是屏幕。

bash logs tee exec

42
推荐指数
2
解决办法
9万
查看次数

使用 tee 将中间结果输出到 stdout 而不是文件

我知道要在处理的中间阶段捕获管道的内容,我们使用 tee as ls /bin /usr/bin | sort | uniq | tee abc.txt | grep out,但是如果我不想将uniq 之后内容重定向到 abc.txt而是 要筛选(通过 stdout,当然),以便作为最终结果,我将在屏幕上显示 uniq 之后的中间内容以及 grep 之后的内容。

command-line bash tee

30
推荐指数
2
解决办法
2万
查看次数

`:w !sudo tee %` 是如何工作的

如果您在 vim 中打开一个您无权写入的文件,然后决定需要更改它,您可以在不退出 vim 的情况下编写更改,这样做:w !sudo tee %
我不明白这是如何工作的。你能剖析一下吗?
我理解这:w部分,它将当前缓冲区写入磁盘,假设已经有一个与之关联的文件名,对吗?
我也理解!哪个执行sudo tee命令并%代表当前缓冲区内容对吗?
但仍然不明白这是如何工作的。

vim sudo tee

30
推荐指数
2
解决办法
1万
查看次数

为什么“ping”在重定向输出时不输出摘要?

我可以 ping google.com几秒钟,当我按Ctrl+时C,底部会显示一个简短的摘要:

$ ping google.com
PING google.com (74.125.131.113) 56(84) bytes of data.
64 bytes from lu-in-f113.1e100.net (74.125.131.113): icmp_seq=2 ttl=56 time=46.7 ms
64 bytes from lu-in-f113.1e100.net (74.125.131.113): icmp_seq=3 ttl=56 time=45.0 ms
64 bytes from lu-in-f113.1e100.net (74.125.131.113): icmp_seq=4 ttl=56 time=54.5 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3009ms
rtt min/avg/max/mdev = 44.965/48.719/54.524/4.163 ms
Run Code Online (Sandbox Code Playgroud)

但是,当我使用 执行相同的重定向输出到日志文件时tee,不会显示摘要:

$ ping google.com | tee log
PING google.com (74.125.131.113) 56(84) …
Run Code Online (Sandbox Code Playgroud)

linux signals ping tee

30
推荐指数
2
解决办法
3255
查看次数

直接输出到管道和标准输出

有没有办法通过管道传输命令的输出并将其定向到stdout

例如,fortune打印一个幸运饼干stdout并将其通过管道传输到下一个命令:

$ fortune | tee >(?stdout?) | lolcat 
"...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and
the Ugly)."
(By Matt Welsh)
Run Code Online (Sandbox Code Playgroud)

bash pipe tee stdout

27
推荐指数
2
解决办法
2万
查看次数

输出到 stdout 并同时 grep 到文件中

我有一个将文本输出到stdout. 我想在我的终端中看到所有这些输出,同时我想过滤一些行并将它们保存在一个文件中。例子:

$ myscript
Line A
Line B
Line C

$ myscript | grep -P 'A|C' > out.file

$ cat out.file
Line A
Line C
Run Code Online (Sandbox Code Playgroud)

我想在终端中查看第一个命令的输出,并将第二个命令的输出保存在一个文件中。同时。我尝试使用tee,但没有结果,或者更好,结果相反

grep pipe tee stdout

26
推荐指数
3
解决办法
5万
查看次数

tee 标准输出到标准错误?

我想将标准输出从一个进程发送到另一个进程的标准输入,但也发送到控制台。例如,将 stdout 发送到 stdout+stderr。

例如,我的git edit别名如下:

git status --short | cut -b4- | xargs gvim --remote
Run Code Online (Sandbox Code Playgroud)

我希望将文件名列表发送到屏幕以及xargs.

那么,是否有类似tee的实用程序可以做到这一点?这样我就可以执行以下操作:

git status --short | \
    cut -b4- | almost-but-not-quite-entirely-unlike-tee | \
    xargs gvim --remote
Run Code Online (Sandbox Code Playgroud)

io-redirection tee stdout stdin

21
推荐指数
2
解决办法
4535
查看次数

是否可以将一个命令的输出重定向到多个命令中?

据我所知,我可以使用 tee 命令将标准输出拆分到屏幕和其他文件上:

command -option1 -option2 argument | tee file1 file2 file3 
Run Code Online (Sandbox Code Playgroud)

是否可以使用 tee 将输出重定向到命令而不是文件,以便理论上我可以创建命令链?

command-line pipe tee

21
推荐指数
3
解决办法
1797
查看次数

如何终止 Linux tee 命令而不终止它接收的应用程序

我有一个 bash 脚本,只要 Linux 机器开机就可以运行。我按如下所示启动它:

( /mnt/apps/start.sh 2>&1 | tee /tmp/nginx/debug_log.log ) &
Run Code Online (Sandbox Code Playgroud)

启动后,我可以在ps输出中看到 tee 命令,如下所示:

$ ps | grep tee
  418 root       0:02 tee /tmp/nginx/debug_log.log
3557 root       0:00 grep tee
Run Code Online (Sandbox Code Playgroud)

我有一个函数可以监视tee生成的日志的大小,并在日志达到一定大小时终止tee命令:

monitor_debug_log_size() {
                ## Monitor the file size of the debug log to make sure it does not get too big
                while true; do
                                cecho r "CHECKING DEBUG LOG SIZE... "
                                debugLogSizeBytes=$(stat -c%s "/tmp/nginx/debug_log.log")
                                cecho r "DEBUG LOG SIZE: $debugLogSizeBytes"
                                if [ $((debugLogSizeBytes)) …
Run Code Online (Sandbox Code Playgroud)

linux scripting kill pipe tee

20
推荐指数
1
解决办法
4996
查看次数

标签 统计

tee ×10

pipe ×4

bash ×3

linux ×3

stdout ×3

command-line ×2

io-redirection ×2

exec ×1

grep ×1

kill ×1

logs ×1

ping ×1

scripting ×1

signals ×1

stdin ×1

sudo ×1

vim ×1