问题描述
在OSX使用bash。我该如何设置我的外壳,使其覆盖某个文件,我最近命令的输出?这将是用于查看/搜索/分析,我没有先见之明,管到一个文件大输出真的很方便。感谢您的帮助!
Using bash on OSX. How can I set up my shell so that it overwrites a certain file with the output of my most recent command? This would be really convenient for viewing/searching/analyzing large outputs that I didn't have the foresight to pipe to a file. Thanks for the help!
推荐答案
使用剧本
键,你的命令和它们的输出从存储在日志文件中,直到您退出剧本
。
Use script
and your commands and their output are stored in a log file until you exit from script
.
script mylogfile.output
运行此命令后,就回到了bash命令提示符,你可以继续你的bash会话正常。所有命令和输出中被保存到mylogfile.output。
After running this command, you are back at the bash command prompt and you can continue your bash session as normal. All commands and ouput are saved to "mylogfile.output".
所以它会自动启动你可以把它放在你的〜/ .bashrc文件如下:
You could put this in your ~/.bashrc file so it starts automatically as follows:
[ -n "$PS1" -a -z "$SCRIPT_STARTED" ] || export SCRIPT_STARTED=$$
[ "$SCRIPT_STARTED" -eq $$ ] && script -q ~/mylogfile.output
在-q选项,可以悄悄地开始这是〜/ .bashrc中
命令安全。
这篇关于在bash自动发送最后一个命令的输出到一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!