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

方案一: 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终止录制。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值