将命令固定到bash历史记录?

时间:2018-10-02 12:45:10

标签: linux bash

在bash shell中,我使用 System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; WSHttpBinding binding = new WSHttpBinding(); binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; //Creates ServiceClient, attach transport-binding, Endpoint and the loaded certificate Services service = new Services (binding, new EndpointAddress(EndPoint)); X509Certificate2 cert = new X509Certificate2( ApplicationSetting.CertificateFilePath, ApplicationSetting.PrivateKeyPassword, X509KeyStorageFlags.PersistKeySet ); service.ClientCredentials.ClientCertificate.Certificate = cert; service.Endpoint.EndpointBehaviors.Add(new CustomMessageInspector()); Response response; try { response = service.Callservice(g110Request); } catch (Exception ex) { log.Error(ex.ToString()); throw; } ctrl-r查找旧命令。有时找不到它们。我猜主要是因为我关闭了终端窗口的顺序或它们太旧了。我知道HISTSIZE和HISTIGNORE。

是否存在某种方式将可能由正则表达式定义的特定命令“固定”到history | grep ...?让他们“永远”呆在那里。 (我正在考虑制作一个perl cronjob来操纵〜/ .bash_history,但如果我不必...)。

3 个答案:

答案 0 :(得分:3)

没有,但我认为您需要的是别名。喜欢命令吗?做一个别名。

alias pinthis="crazy -command | I -wont remember.later"

答案 1 :(得分:0)

如果确定这些“特定命令”正确,则可以在bashrc中使用别名,这是一种更好,更简单的方法。

就像将以下条目添加到您的〜/ .bashrc

alias <aliasname>='<command>'

现在,每次您要使用命令时,都可以使用别名。

例如,我经常使用git commit origin / master,因此〜/ .bashrc中存在以下条目

alias gitcm='git commit origin/master'

这使我只能键入gitcm来调用命令。

答案 2 :(得分:0)

如果您不想创建别名,则可能需要使用 histexpand 选项。

以下是我的历史记录文件的一个示例;

  900  history 3
  901  ls -l
  902  cd /var/log/
  903  ls -l
  904  history 5

如果启用了 histexpand 选项,则-en默认启用-,当您键入!901时,它将自动从历史记录文件中运行ls -l

相关问题