bash 如何查找被触发的命令的日期明智的历史记录

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

How to find date wise history of commands being fired

bashhistory

提问by chetan

How can I make the history command display the date and time information in addition to the command line?

如何让history命令除了命令行显示日期和时间信息?

回答by paldepind

The history of executed commands is stored by your shell. Try adding something like this to you ~/.bashrc

已执行命令的历史记录由您的 shell 存储。尝试向您添加这样的内容~/.bashrc

export HISTTIMEFORMAT="%m/%d - %H:%M:%S: "

It will change the HISTTIMEFORMATvariable and bash will store a timestamp in its history accordingly. Then your history will look like this

它将更改HISTTIMEFORMAT变量,bash 将相应地在其历史记录中存储时间戳。那么你的历史将是这样的

487  08/16 - 16:12:01: cd Downloads
488  08/16 - 16:12:04: ls -a
489  08/16 - 16:12:37: cat README | less
490  08/16 - 16:12:58: pkg-config --list-all | grep webkit
491  08/16 - 16:13:04: history

Available identifiers are

可用的标识符是

%d - Day
%m - Month
%y - Year
%T - Time
%H - Hours
%M - Minutes
%S - Seconds