【问题标题】:Delete bash history in Centos 6.2在 Centos 6.2 中删除 bash 历史记录
【发布时间】:2016-10-05 19:16:23
【问题描述】:

我不小心将一大块文本复制到我的 Centos6.2 shell 中,这在我的 bash 历史记录中很烦人,我该如何删除它?

我尝试运行history -d {{ number }},但下次我打开外壳时它又回来了:(

另外,当我尝试在 for i in list 循环中使用 history -d $i 时 ,我认为它没有删除任何东西,因为它们在 subshel​​ls 中运行。

【问题讨论】:

  • rm ~/.bash_history 呢?
  • 你想摆脱所有历史命令吗?
  • 一切都会好起来的,但我很想知道是否可以在任何特定日期或时间完成?
  • 使用:vim ~/.bash_historyselectively delete lines 你不想...
  • 另外,如果你碰巧在终端上复制粘贴了一大段行(这本身就是一个安全风险,但无论如何,你已经犯了那个错误......)&你不想要写入文件的历史记录,设置HISTFILE=/dev/null

标签: linux bash shell


【解决方案1】:

您可以使用以下命令来清理 .bash_history 文件:

history -w 
history -c

要删除特定行,请使用以下命令:

history -d <line_number> // deletes the line from history in memory

history -w 会将当前内存中的更改写入 .bash_history 文件。

【讨论】:

  • 感谢工作完美
猜你喜欢
  • 2011-02-10
  • 1970-01-01
  • 2020-09-11
  • 1970-01-01
  • 2014-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-15
相关资源
最近更新 更多