执行命令而不将其保留在历史记录中 [英] Execute a command without keeping it in history

查看:49
本文介绍了执行命令而不将其保留在历史记录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一些命令,但是我不想将它们存储在命令历史记录中.这样,没人能在 .bash_history 文件中进行搜索.

I want to execute some commands, but I don't want to store them in the command history. So that nobody will be able to search them in the .bash_history file.

有没有一种方法可以这样执行Bash命令?

Is there a way how to execute Bash commands this way?

推荐答案

以空格开头的命令将不会包含在历史记录中.

Start your command with a space and it won't be included in the history.

请注意,这确实需要设置环境变量 $ HISTCONTROL .

Be aware that this does require the environment variable $HISTCONTROL to be set.

  • 检查以下命令是否返回 ignorespace ignoreboth :

 echo $HISTCONTROL

  • 要添加环境变量(如果缺少),可以将以下行添加到Bash配置文件中.例如,保存到%HOME/.bashrc .

     export HISTCONTROL=ignorespace
    

  • 再次获取配置文件后,空格前缀的命令将不会被写入 $ HISTFILE .

    After sourcing the profile again, space-prefixed commands will not be written to $HISTFILE.

    这篇关于执行命令而不将其保留在历史记录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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