How to delete a file with corrupt filename?
There are a bunch of options for deleting files with non-ascii filenames.
I was able to create and delete a file with the filename under discussion by using ANSI C quoting:
# Create the offending file
touch $'\x3f\x3f\x5b\x3f\x3f\x02\x3f\x3f\xd8\xa9\x3f\x58\x0a'
# Verify that the file was created
ls -lib
# Remove the offending file
rm $'\x3f\x3f\x5b\x3f\x3f\x02\x3f\x3f\xd8\xa9\x3f\x58\x0a'
Take a look at this post:
- identify files with non-ASCII or non-printable characters in file name
Here's a command taken from that post that should delete all files in the current directory whose names contain non-ascii characters:
LC_ALL=C find . -maxdepth 0 -name '*[! -~]*' -delete
You can modify the glob pattern or use a regular expression in order to narrow down the matches.
Here's another relevant post:
- How to delete a file with a weird name?
There's a suggestion there to try deleting by inode. First run ls -lib
to find the inode of the offending file, and then run the following command to delete it:
find . -maxdepth 1 -inum ${INODE_NUM} -delete
You might also find the following article to be generally useful:
- Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems
Always double check on which partition your files are ;-)
Turns out the bad file was not on my root partition but on a cifs
mount.
To get rid of the file the solution was just like there:
Delete the file on the target maschine. There the rm
command works normally.