删除以双符号和感叹号开头的文件

Remove file starting with double ampersand and exclamation

我有一个名为 && !!

的文件

如何删除这个文件?

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': No such file or directory

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

我是怎么到这里的?

  1. 打开Vim

  2. :e && !!

  3. :wq

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

rm -- '&& !!'

历史扩展经常让我感到困惑,而且我从未发现该功能的用途,所以我选择通过将 set +H 添加到我的 .bashrc 文件来禁用它。

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

双引号扩展其内容。