如何在linux bash中删除历史记录

问题描述 投票:0回答:1

在我的Pi上闲逛Linux并遇到了这个问题。我发现您可以使用命令history -d linenumber删除某行,但是如果我想删除范围(我认为这更实用)该怎么办?因此,我查找了如何在几个地方循环播放。两种循环方式都适用于回显,但不适用于history命令。我认为这是因为“历史记录”实际上不是命令。但是为什么这很重要?有一个简单的方法吗?我不知道在Linux bash中可能发生循环,所以现在我很好奇!这是我所做的:

pi@raspberry:~$ for ((i=258;i<=262;++i)); do "history -d $i"; done; // //由于引号不正确,给出: -bash: history -d 258: command not found -bash: history -d 259: command not found -bash: history -d 260: command not found -bash: history -d 261: command not found -bash: history -d 262: command not found

以下内容应该可以使用(但不能):

pi@raspberry:~$ for i in {5..10}; do history -d $i; done; -bash: history: 5: history position out of range

我在这里找到了一篇文章:https://superuser.com/questions/649859/history-position-out-of-range-when-calling-history-from-bash-script

...但他们一点也不清晰,并说了一些话,需要从源头而不是执行它,这对我实际上没有任何意义。如果无法通过命令行完成,请这样说。否则,我将重新学习Python,如果这样做是合乎逻辑的,那就很高兴了。

谢谢

bash loops for-loop history
1个回答
0
投票

假设条目存在。

如果要删除条目258到262,则将条目258删除五次。

© www.soinside.com 2019 - 2024. All rights reserved.