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: