清除 bash 命令历史记录
清空当前会话历史并删除已保存的历史文件。
运行 history -c && rm -f ~/.bash_history,同时清空内存列表和历史文件。
01命令
命令
$ history -c && rm -f ~/.bash_history02作用说明
~/.bash_history 在 shell 退出时写入,里面记录了一切——包括你粘贴在命令里的密码、连过的服务器。history -c 清空当前 shell 内存里的列表,删除文件则抹掉过去的记录,两者一起执行才算清干净。如果用 zsh,历史文件是 ~/.zsh_history。
03风险
!注意: 删除无法恢复——你自己的有用记录也会一并丢掉;已经开着的终端退出时会把各自的历史写回去,请先关闭它们或逐一清理。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- bash(1) — manual page依据: history -c clears the in-memory history list; the HISTFILE (~/.bash_history) is written when the shell exits, so the file must also be removed.
最后验证: 2026-09-18 · 分类: 安全与隐私