你可以prevent从进入在bash shell命令历史记录的命令? [英] Can you prevent a command from going into the bash shell command history?

查看:87
本文介绍了你可以prevent从进入在bash shell命令历史记录的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来prevent被添加到bash shell中的命令历史记录的命令?

Is there a way to prevent a command from being added to the bash shell's command history?

我希望能够prevent一定的危险被添加到历史命令,如 RM -rf〜/一些/ DIR ,所以它不是由pressing向上箭头达到previous命令我使用。以这种方式,它不会是可能意外地重复这些命令之一

I would like to be able to prevent certain "dangerous" commands from being added to the history, such as "rm -rf ~/some/dir", so that it is not accessible to me by pressing the up-arrow to reach previous commands. In this way, it would not be possible to accidentally repeat one of these commands.

我想问的原因是,我使用的向上箭头很多访问shell的历史记录previous命令,并常常陷入自己即将打在我的输入以为是正确的命令,才意识到我即将做一些愚蠢/烦人/危险。我不喜欢 RM 取值等漂浮在我的壳历史的想法,等我踩到他们!

The reason I ask is that I use the up arrow a lot to access previous commands in the shell history, and have often caught myself about to hit enter on what I thought was the correct command, only to realise that I was about to do something stupid/annoying/dangerous. I don't like the idea of rms etc floating around in my shell history, waiting for me to step on them!

(注:我知道一个可以设置模式在HISTIGNORE,但什么将是很好的东西可以应用在每个命令的基础上,这将成为良好的习惯,除非有一个聪明的办法来实现。这个使用HISTIGNORE,我错过了什么?)

(Note: I am aware that one can set up patterns in HISTIGNORE, but what would be nice is something one can apply on a per-command basis, which would become good a habit. Unless there is a clever way to achieve this using HISTIGNORE that I have missed?)

推荐答案

在新的Bash版本,你可以只需在命令开头添加一个空格。 :)
如果默认情况下不工作,添加[\\ t] *以HISTIGNORE。 (如在评论中提到。THX)

On newer Bash Versions you could simply add a space at the beginning of your command. :) If it doesn't work by default, add [ \t]* to HISTIGNORE. (As mentioned in the comments. thx)

这篇关于你可以prevent从进入在bash shell命令历史记录的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆