2

是否可以将命令的输出放入文件中?我试着做一个

echo history > history.txt

但它将文本历史记录改为该文件。

4

2 回答 2

8

Just do history > history.txt without the echo. That should do it. When you do echo history, you are telling unix to print history to screen rather then execute it, which is why echo history > history.txt only contains the word history.

于 2012-06-09T19:25:34.500 回答
3

除非您想从当前会话中获得不成文的历史记录,否则给出的示例可能是不必要的。您的 ~/.bash_history 或类似文件已经保存了您过去会话的历史记录。

您可以使用 附加当前会话的历史记录history -w。然后您的 ~/.bash_history 文件将是最新的,包括当前会话中的项目。

于 2012-06-09T19:31:03.410 回答