在linux中删除文件名“-r”

我无法使用rm -rf -r删除名为-r的文件名是否有任何特殊技巧将其删除?

在Linux或类Unix系统中,您可能会遇到包含以下特殊字符的文件名:

 - -- ; & $ ? * White spaces, backslashes and more. 

问题和解决scheme

提示#1:在文件名的开头尝试一个./

语法如下删除名为'-file'的文件:

$ rm -v ./-file

删除`./-file'

提示#2:尝试一个 – 在文件名的开头

 A -- signals the end of options and disables further option processing by shell. Any arguments after the -- are treated as filenames and arguments. 

$ rm – – 文件

$ rm – –file

$ rm – '@#$%^&file'

$ rmdir – '–dirnameHere'

正如在手册页中所描述的那样:

要删除名称以“ – ”开头的文件,例如“-foo”,请使用以下命令之一:

  rm -- -foo rm ./-foo 

所以,在你的情况下:

 rm -- -r 

要么

 rm ./-r