linux–.bash_history:它总是记录我发出的每个命令吗?

linux–.bash_history:它总是记录我发出的每个命令吗?,第1张

概述我希望能够查看我的命令历史记录(一直回到用户的开头).是否有保证.bash_history将继续附加?如果存在文件开始被截断的限制(希望从头开始)有没有办法删除该限制?最佳答案有许多环境变量可以控制历史在bash中的工作方式. bash手册页的相关摘录如下: HISTCONTROL A colon-separated list of

我希望能够查看我的命令历史记录(一直回到用户的开头).

是否有保证.bash_history将继续附加?

如果存在文件开始被截断的限制(希望从头开始)有没有办法删除该限制?

最佳答案有许多环境变量可以控制历史在bash中的工作方式. bash手册页的相关摘录如下:

   HISTCONTRol          A colon-separated List of values controlling how commands are saved on the history List.  If the List of values includes ignorespace,lines  which          begin  with  a space character are not saved in the history List.  A value of ignoredups causes lines matching the prevIoUs history entry to not be          saved.  A value of ignoreboth is shorthand for ignorespace and ignoredups.  A value of erasedups causes all prevIoUs  lines  matching  the  current          line  to be removed from the history List before that line is saved.  Any value not in the above List is ignored.  If HISTCONTRol is unset,or does          not include a valID value,all lines read by the shell parser are saved on the history List,subject to the value of HISTIGnorE.   The  second  and          subsequent lines of a multi-line compound command are not tested,and are added to the history regardless of the value of HISTCONTRol.   HISTfile          The  name  of the file in which command history is saved (see HISTORY below).  The default value is ~/.bash_history.  If unset,the command history          is not saved when an interactive shell exits.   HISTfileSIZE          The maximum number of lines contained in the history file.  When this variable is assigned a value,the history file is truncated,if necessary,by          removing  the  oldest entrIEs,to contain no more than that number of lines.  The default value is 500.  The history file is also truncated to this          size after writing it when an interactive shell exits.   HISTIGnorE          A colon-separated List of patterns used to decIDe which command lines should be saved on the history List.  Each pattern is anchored at the  begin-          ning  of  the line and must match the complete line (no implicit `*' is appended).  Each pattern is tested against the line after the checks speci-          fIEd by HISTCONTRol are applIEd.  In addition to the normal shell pattern matching characters,`&' matches the prevIoUs history line.  `&'  may  be          escaped  using  a  backslash; the backslash is removed before attempting a match.  The second and subsequent lines of a multi-line compound command          are not tested,and are added to the history regardless of the value of HISTIGnorE.   HISTSIZE          The number of commands to remember in the command history (see HISTORY below).  The default value is 500.

直接回答您的问题:

没有保证,因为历史可以被禁用,一些命令可能不被存储(例如,以空格开始)并且可能对历史大小施加限制.

至于历史大小限制:如果你取消设置HISTSIZE和HISTfileSIZE:

unset HISTSIZEunset HISTfileSIZE

你将阻止shell截断你的历史文件.但是,如果您运行的shell实例设置了这两个变量,它将在退出时截断您的历史记录,因此解决方案非常脆弱.如果您绝对必须维护长期shell历史记录,则不应依赖shell并定期将文件(例如使用cron作业)复制到安全位置.

历史截断始终首先删除最旧的条目,如上面的联机帮助页摘录中所述.

总结

以上是内存溢出为你收集整理的linux – .bash_history:它总是记录我发出的每个命令吗?全部内容,希望文章能够帮你解决linux – .bash_history:它总是记录我发出的每个命令吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1047214.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存