删除以双“&”号和惊叹号开头的文件

时间:2018-12-05 14:30:42

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

我有一个名为&& !!

的文件

如何删除此文件。

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的方式

我该怎么办?

打开vim

:e && !!

:wq

2 个答案:

答案 0 :(得分:6)

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

rm -- '&& !!'

历史记录扩展使我绊倒的次数比我喜欢的多,并且我从未发现该功能的用途,因此我选择通过在set +H上添加.bashrc来禁用它。

答案 1 :(得分:4)

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

双引号会扩展其内容。

相关问题