Delete a corrupt file in Linux
How I can delete this file? I think it is a corrupt file in a VFAT file system.
????????? ? ? ? ? ? 100.jpg
Solution 1:
One possibility is to find out the inode
number of the file, which you can do by running ls -i
. This will return two columns -- the first being the inode, and the second being the filename. You can then use the find
command to select only the file with that specific inode, and delete it.
sh-4.1$ ls -i .
17921 somefile.ods
169 someotherfile.conf
305 -????????? ? ? ? ? ? 100.jpg
18048 yetanotherfile.jpg
sh-4.1$ find . -maxdepth 1 -inum 305 -ok rm '{}' \;
< rm ... -????????? ? ? ? ? ? 100.jpg > ? y
Since the inode is most likely unique to the file (assuming no hardlinks), this will allow you to delete without the risks inherent with wildcards. The maxdepth
and the ok
options of the find command just make it even less likely that you'll hit the wrong file by accident.
Solution 2:
I'm not sure if any of the answers here have actually had the issue Stig reported. I just ran into this problem myself on my ext4 filesystem:
# ls -l /tmp/dependencies/
ls: cannot access /tmp/dependencies/easy-rsa-master: No such file or directory
total 0
?????????? ? ? ? ? ? easy-rsa-master
# ls -i /tmp/dependencies/
ls: cannot access /tmp/dependencies/easy-rsa-master: No such file or directory
? easy-rsa-master
# rm -r /tmp/dependencies
rm: descend into directory ‘dependencies’? y
rm: cannot remove ‘/tmp/dependencies/easy-rsa-master’: No such file or directory
rm: remove directory ‘dependencies’? y
rm: cannot remove ‘dependencies’: Directory not empty
The file itself was corrupt along with its file attributes. ls -i clearly shows no inode ID. No usage of rm will do the trick. Even rm -rf traverses into the directory and tries to delete the file directly (and silently).
My solution was to recreate the directory without the offending file. Then you can move the directory to another location, like /tmp. It'll be gone after a reboot or whenever your distro cleans the /tmp directory (hopefully).