How to Delete Files with Special Characters or Corrupted Names in Linux

When a program or system malfunctions, it can lead to file names containing special characters or becoming corrupted. Sometimes, using the rm command directly may not work, as shown in the image below:How to Delete Files with Special Characters or Corrupted Names in LinuxHere are several methods to delete such files:

1

Use rm — or rm ./ If the file name starts with a ‘-‘, directly deleting it will result in an error. You can use the command:

rm — -test.txt

or

rm ./-test.txt

How to Delete Files with Special Characters or Corrupted Names in Linux

2

Delete by inode number

1) Use ls -i to find the inode number of the file. For example, if the inode number is 598260:

How to Delete Files with Special Characters or Corrupted Names in Linux

2) Use the find command to delete it:

find ./ -inum 598260 -exec rm ‘{}’ \;

or

rm `find . -inum 598260`

How to Delete Files with Special Characters or Corrupted Names in Linux

Leave a Comment