简体   繁体   English

linux 删除文件名中带有特殊字符的文件

[英]Delete files with special characters in filenames in linux

I've accidentally created files with names that won't allow me to delete them:我不小心创建了名称不允许我删除它们的文件:

-d
--header

Doing the following has no effect:执行以下操作无效:

rm -f '-d'
rm -f '--header'
unlink ('-d');
unlink ('--archive');

Unlink gives an error:取消链接会出现错误:

unlink: invalid option -- 'd'
Try 'unlink --help' for more information.

How can I get rid of these files?我怎样才能摆脱这些文件?

Use -- to tell BASH that the command options has ended, then, all other parameters are treated as positional parameters so they wont be interpreted by rm ;使用--告诉 BASH命令选项已经结束,然后,所有其他参数都被视为位置参数,因此它们不会被rm解释;

rm -- --header
rm -- --d

Screenshot of example示例截图

More on -- : What does “--” (double-dash) mean?更多关于--“--”(双破折号)是什么意思?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM