【问题标题】:Remove file starting with double ampersand and exclamation删除以双 & 和感叹号开头的文件
【发布时间】:2018-12-05 14:30:42
【问题描述】:

我有一个名为&& !!的文件

如何删除此文件?

On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    && !!
rm -- "&& !!"

结果:

rm: cannot remove '&& git st': 没有这样的文件或目录

您可能已经猜到了,git st 是我的 git status 方式。

我是怎么到这里的?

  1. 打开 Vim

  2. :e &amp;&amp; !!

  3. :wq

【问题讨论】:

    标签: bash unix vim windows-subsystem-for-linux


    【解决方案1】:

    您的rm -- "&amp;&amp; !!" 尝试失败,因为历史扩展将!! 替换为先前执行的命令。您可以通过用单引号引用文件名来避免这种情况,因为您不需要扩展内容:

    rm -- '&& !!'
    

    历史扩展让我犯错的次数比我喜欢的要多,而且我从未找到该功能的用途,因此我选择通过将set +H 添加到我的.bashrc 文件来禁用它。

    【讨论】:

      【解决方案2】:

      像这样使用单引号:rm -- '&amp;&amp; !!'

      双引号扩展其内容。

      【讨论】:

        猜你喜欢
        • 2012-03-06
        • 2012-07-07
        • 1970-01-01
        • 1970-01-01
        • 2010-12-10
        • 2017-03-02
        • 2012-10-15
        • 2013-10-04
        • 2021-11-02
        相关资源
        最近更新 更多