DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Linux命令行中删除特殊名字的文件


今天下载了一个zip文件,解压后出现一个文件名为"-==(czRGsl)==-.mp4"的文件,删除时出现下面的错误:

[chad@chadleebj ~]$ rm *.mp4
rm: invalid option -- '='
Try `rm ./'-==(czRGsl)==-.mp4'' to remove the file `-==(czRGsl)==-.mp4'.
Try `rm --help' for more information

加单引号和转义符都无效:

[chad@chadleebj ~]$ rm '-==(czRGsl)==-.mp4'
rm: invalid option -- '='
Try `rm ./'-==(czRGsl)==-.mp4'' to remove the file `-==(czRGsl)==-.mp4'.
Try `rm --help' for more information.

[chad@chadleebj ~]$ rm \-\=\=\(czRGsl\)\=\=-.mp4
rm: invalid option -- '='
Try `rm ./'-==(czRGsl)==-.mp4'' to remove the file `-==(czRGsl)==-.mp4'.
Try `rm --help' for more information

错误原因是将文件名的第一个字符"-"当成了选项符号,又没有"="这个选项造成的,所以首先要在rm后加"--"告诉命令后面的"-"不是选项符号:

[chad@chadleebj ~]$ rm -- -==(czRGsl)==-.mp4
-bash: syntax error near unexpected token `('

其中的括号需要转义:

[chad@chadleebj ~]$ rm -- -==\(czRGsl)==-.mp4
-bash: syntax error near unexpected token `)'

[chad@chadleebj ~]$ rm -- -==\(czRGsl\)==-.mp4

搞定。



Published

Jan 13, 2015

Last Updated

Jan 13, 2015

Category

Tech

Tags

  • linux 158
  • rm 1
  • shell 46

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor