虚拟主机域名注册-常见问题 → 服务器知识 → 操作系统 | ||||
你可以使用历史记录命令来清除所有的历史记录或选定的命令行。在本教程中,您将学习如何在Linux、MacOS和类似Unix的系统中清除bash历史记录中的特定命令。 如何查看行号的历史记录? 只需输入history命令: $ history ![]() 默认情况下,历史记录存储在~/.bash_history文件中。但是,名为$ HISTFILE的bash变量定义了保存命令历史记录的文件名。如果未设置,则退出shell时不会保存命令历史记录。使用printf命令/ echo命令显示当前设置: echo "$HISTFILE" printf "Bash history file - %s\n" $HISTFILE 如何在Linux中删除历史记录中的单条命令编号为1013的命令 ## Delete the bash history entry at offset OFFSET ## history -d offset history -d number history -d 1013 验证一下: $ history ![]() Linux bash shell从历史文件中删除单个命令 在位置OFFSET处删除bash历史记录条目。负偏移量从历史记录列表的末尾算起。 如何删除所有历史记录? 想删除所有的bash历史记录?试试下面的语法命令: $ history -c 添加上面的命令到你的〜/ .bash_logout中的文件,以便在注销的时候进行清理: $ cat /dev/null > ~/.bash_history && history -c 将-c传递给history命令删除所有条目$ {} HISTFILE要清除历史记录列表。 提示:像专家一样控制bash历史记录 首先,您可以通过在〜/ .bashrc文件中附加以下配置选项来增加bash历史记录的大小: ## Set the maximum number of lines contained in the history file ## HISTFILESIZE=5000000 ## Set the number of commands to remember in the command history ## HISTSIZE=10000 ## Append it ## shopt -s histappend ###### # Controlling how commands are saved on the history file ## # ignoreboth means: ## # a) Command which begin with a space character are not saved in the history list ## # b) Command matching the previous history entry to not be saved (avoid duplicate commands) ## ###### HISTCONTROL=ignoreboth 保存并关闭文件。 在哪里可以找到有关历史命令的更多信息? 通过键入以下命令来阅读bash手册页: $ man bash 另一个选项是键入以下命令: $ help history 示例输出: ![]()
|
||||
>> 相关文章 | ||||
没有相关文章。 |