bash linux服务器上保存命令历史的所有位置在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39877237/
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 15:15:47  来源:igfitidea点击:

Where are all the locations where command history is saved on linux server

linuxbashhistory

提问by Colin

I know that the history can be seen by just running the command 'history' but I am wondering where else commands may be stored.

我知道只需运行命令“history”就可以看到历史记录,但我想知道其他命令可能存储在哪里。

回答by mrks

You can check the location of the (only) history file of your shell using echo $HISTFILE. Most likely, this is what you are looking for.

您可以使用echo $HISTFILE. 最有可能的是,这就是您正在寻找的。

Single commands may store additional information. For example, sudomay store the commands executed as root in the system log. If you run the mysql CLI, it would store its history (by default) in ~/.mysql_history.

单个命令可以存储附加信息。例如,sudo可以将作为 root 执行的命令存储在系统日志中。如果您运行 mysql CLI,它会将其历史记录(默认情况下)存储在~/.mysql_history.

回答by chepner

Command history is a shell-specific feature stored on a per-user basis. The historycommand displays what the current instance has in memory.

命令历史是基于每个用户存储的特定于 shell 的功能。该history命令显示当前实例在内存中的内容。

The historycommand takes options -r, -w, and -ato read from, write to, or append to (respectively) a default history file, which is ~/.bash_historyor the name stored in the HISTFILEvariable.

history命令采用 options -r-w-a来读取、写入或附加到(分别)默认历史文件,该文件是~/.bash_history或 存储在HISTFILE变量中的名称。

Generally speaking, though, the shell could be configured to read and write history to an arbitrary file; there's no way to know where history could be stored without being familiar with a particular user's shell configuration files or scripts.

不过,一般来说,shell 可以配置为读取和写入任意文件的历史记录;如果不熟悉特定用户的 shell 配置文件或脚本,就无法知道历史记录的存储位置。

回答by Chim Chimz

By default it's stored in ~/.bash_history

默认情况下它存储在 ~/.bash_history