Sometimes we have to remove files with weird names, like “-h”. rm -h does not work because the shell sees “-h” as a command option.
So, how can we delete these file? Simple: by it’s inode.
A file’s inode can be found with ls -li or stat.
Every file has an unique inode (big number). The inode is like the user’s UID.
$ ls -li
428316 -rw-r--r-- 1 root root 0 2012-05-31 22:21 -h
The inode is the 6 digits number from the first column of the ls -li output.
Finding a file’s inode with stat:
$ stat -- -h | grep -i inode
Device: 801h/2049d Inode: 428316 Links: 1
Now, I will delete -h by it’s inode with the following command:
find . -inum INODENUMBER -exec rm -i {} +
Type y for yes and n for no, in order to delete the file, or not.
$ find . -inum 428316 -exec rm -i {} +
rm: remove regular empty file `./-h'? y
ls -l
total 0
The -h file can also be deleted with rm – – “-h” . (there is no space between the two minus characters)
$ ls
-h
$ rm -- "-h"
Hi! Do you use Twitter? I’d like to follow you if that would be ok. I’m definitely enjoying your blog and look forward to new posts.
yes, you can follow us on twitter: @LinuxGeekster
Thanks for finally writing about >How to remove files by their inode | LinuxG.net <Liked it!