Delete a file with garbled characters or special characters in Linux.

Source: Internet
Author: User

Delete a file with garbled characters or special characters in Linux.

In Linux, how does one delete a file with garbled characters or special characters.

Today, I encountered a problem where the file name is "-MXV9.log" and an error was reported when I deleted it directly using rm.

[Localhost] rm-MXV9.log
Rm: illegal option -- M
Rm: illegal option -- X
Rm: illegal option -- V
Rm: illegal option -- 9
Rm: illegal option --.
Rm: illegal option -- l
Rm: illegal option -- o
Rm: illegal option -- g
Usage: rm [-Rfir] file...

I started to think about deleting with quotation marks and found that deleting with quotation marks also reported the illegal option error.

I found some materials and found that such files can be deleted in this way.

First ls-I finds the inode of the file, and then uses the find command to delete it.

[Localhost] ls-ilrt

100985-rw-r -- 1 tbcs users 0 Apr 18 :32-MXV9.log

100985 In the first column is the inode of the file. You can delete the file by executing the following command on the host:

[Localhost] find./-inum 100985-exec rm {}\;

This method is applicable to the deletion of files with garbled characters or special characters.

For example, if the file name is "*. txt" and rm *. txt is executed directly, all files ending with ". txt" in the folder will be deleted.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.