【linux】将ubuntu终端输出为文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tfcy694/article/details/83997208

方案一: tee

tee --help

用法:tee [选项]… [文件]…
将标准输入复制到每个指定文件,并显示到标准输出。

-a, --append 内容追加到给定的文件而非覆盖
-i, --ignore-interrupts 忽略中断信号
-p diagnose errors writing to non pipes
–output-error[=MODE] set behavior on write error. See MODE below
–help 显示此帮助信息并退出
–version 显示版本信息并退出

MODE determines behavior with write errors on the outputs:
‘warn’ diagnose errors writing to any output
‘warn-nopipe’ diagnose errors writing to any output not a pipe
‘exit’ exit on error writing to any output
‘exit-nopipe’ exit on error writing to any output not a pipe
The default MODE for the -p option is ‘warn-nopipe’.
The default operation when --output-error is not specified, is to
exit immediately on error writing to a pipe, and diagnose errors
writing to non pipe outputs.

echo $PATH | tee hello.log
echo $PATH | tee -a hello.log
echo $PATH | tee -a hello.log hello.txt

方案二:script

script --help

Usage:
script [options] [file]

Make a typescript of a terminal session.

选项:
-a, --append append the output
-c, --command run command rather than interactive shell
-e, --return return exit code of the child process
-f, --flush run flush after each write
–force use output file even when it is a link
-q, --quiet be quiet
-t, --timing[=] output timing data to stderr (or to FILE)
-V, --version output version information and exit
-h, --help display this help and exit

输入指令开始录制脚本:

script -a hello.log

之后所有的终端输出都会写入hello.log的末尾
输入exit命令或ctrl+D终止录制。

猜你喜欢

转载自blog.csdn.net/tfcy694/article/details/83997208