在sh中阻止命令历史访问

2024-03-28 23:52:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我不想访问shell中的shell命令历史记录。它必须暂时封锁,然后我才能释放那个封锁。你知道吗

例如,当我在shell中按up arrow时,它会显示历史中出现的最后一个命令,但当我在shell上按向上箭头时,我不想访问历史

我们能阻止历史访问它吗?你知道吗

我试过set +o history,但目的不同。你知道吗

shell:> ifconfig
shell:> #some shell.py
Login: #when I press up arrow, "ifconfig" comes here as that was last command
Password:

对于登录:它只需要访问输入,不在此处访问历史记录。 接受登录和密码后,我可以再次访问历史记录。你知道吗


Tags: py命令目的历史记录loginsome箭头历史
2条回答

删除向上箭头绑定

bind -r '\e[A'

恢复

bind '"\e[A": previous-history'

检索到previous-history的所有绑定

bind -p | grep previous-history

或者

bind -q previous-history

另请参见

help bind

您可以通过编辑~/.bashrc并添加以下内容来禁用向上箭头键:

bind '"\e[A": '

意思是:绑定Up Arrow Key为空

(需要重新加载或重新打开会话)

要重新启用它,只需删除该行并重新加载.bashrc文件

相关问题 更多 >