bash 如何在一个文件中提取所有命令历史linux

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20297707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:48:56  来源:igfitidea点击:

How to extract all command history in one file linux

bashshellinput-history

提问by user3040487

I know how History command works in linux and also that it only displays the commands typed from terminal from that very directory in which the history command was executed,,Isn't it?My intent is to display all the commands typed(History) by me (as a user per se) .

我知道 History 命令在 linux 中是如何工作的,而且它只显示从执行历史命令的那个目录中的终端键入的命令,不是吗?我的目的是显示所有键入的命令(历史)我(作为用户本身)。

Thanks in advance .

提前致谢 。

回答by

You can use the

您可以使用

history

command, it displays all the history, and is not taking into consideration the 'very directory in which the history command was executed'.

命令,它显示所有历史记录,并且不考虑“执行历史命令的目录”。

You can output it to a file by using

您可以使用以下命令将其输出到文件

history >> file.txt

To see more about the history command, you can visit

要查看有关 history 命令的更多信息,您可以访问

http://www.tldp.org/LDP/GNU-Linux-Tools-Summary/html/x1712.htm

http://www.tldp.org/LDP/GNU-Linux-Tools-Summary/html/x1712.htm

回答by Milovan Toma?evi?

$ history > history_for_print.txt

$ history > history_for_print.txt