Remove file by inode (for hard to remove files)

It is sometimes difficult to remove a file which has special characters in the filename.

In these occasions it is the easiest to remove the file by it's inode.

To find out what inode (number) is linked to what file enter:

ls -li

The result is something like this:

51249160 drwxr-xr-x  2 user group  4096 aug 22 16:16 Desktop
51249164 drwxr-xr-x  5 user group  4096 aug 18 23:04 Documents
51249161 drwxr-xr-x 12 user group 16384 sep  3 17:56 Downloads
54012956 -rw-rw-r--  1 user group     0 sep  3 18:14 file_to_delete.txt

The first column is the inode part, if you want to delete a file, you'll need that number.

Now let's remove the file: file_to_delete.txt

michiel@desktop:~$ find . -inum 54012956 -exec rm -i {} \;
rm: remove regular empty file ‘./file_to_delete.txt’? y

You will see, Linux detects the filename from the inode number, this way you can check if the file is really the file you want to delete.


Use at your own risk.