rm +如何删除特殊字符的文件

我在我的linux机器上有这个文件:

----------9976723563nneh4_-----192.9.200.4 

我试图删除这个文件,但我不能所有看到这里:

需要添加到RM才能删除此文件?

 rm "----------9976723563nneh4_-----192.9.200.4" rm: illegal option -- --------9976723563nneh4_-----192.9.200.4 usage: rm [-fiRr] file ... 

 rm '----------9976723563nneh4_-----192.9.200.4' rm: illegal option -- --------9976723563nneh4_-----192.9.200.4 usage: rm [-fiRr] file ... 

 rm -- ----------9976723563nneh4_-----192.9.200.4 

您需要--为了告诉rm (以及其他所有GNU软件),即使以“ – ”开头,以下所有参数都是文件名。 否则(在你的情况)文件名与选项混淆。 另一种可能性是

 rm ./----------9976723563nneh4_-----192.9.200.4 

编辑1

把这个微不足道的答案称为“伟大的解决scheme”,使我觉得有必要把它提高到一个更高的水平。 基本问题不能解决得更好,但你可以尝试习惯总是做出一个论点。 而一些shell代码(用shell函数代替rm)可以帮助你:

 rm () { local args sep_found=no args=("$@") while [ $# -gt 0 ]; do if [ "--" = "$1" ]; then sep_found=yes break fi shift done if [ "yes" = "$sep_found" ]; then command rm "${args[@]}" else echo "WARNING: rm called without '--' seperator." echo "Please correct the command; aborting." fi } 

你会把它放在例如~/.bashrc

rm的手册页:

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

rm – -foo

所以要删除您的文件,请尝试rm -- ----------9976723563nneh4_-----192.9.200.4