Remove a file on Linux using the inode number

Solution 1:

Some other methods include:

escaping the special chars:

[~]$rm \"la\*

use the find command and only search the current directory. The find command can search for inode numbers, and has a handy -delete switch:

[~]$ls -i
7404301 "la*

[~]$find . -maxdepth 1 -type f -inum 7404301
./"la*

[~]$find . -maxdepth 1 -type f -inum 7404301 -delete
[~]$ls -i
[~]$

Solution 2:

Maybe I'm missing something, but...

rm '"la*'

Anyways, filenames don't have inodes, files do. Trying to remove a file without removing all filenames that point to it will damage your filesystem.

Solution 3:

If you really want to do this - and your use case doesn't really look like you need to at all, you might try file system debugging tools. If you're willing to lose everything, that is.

For example, for ext2/3/4 the debugfs command has a "kill_file" option that seems to take an inode. As mentioned in other responses, this will damage your file system, as there will be directory entries pointing to a non-existent file. Running fsck afterwards may be able to repair this. It's unlikely you can do this on a mounted file system.

But I'd strongly recommend you just use appropriate escaping/quoting and delete such files with the regular rm command as mentioned in an earlier response - and use rm -i for extra safety when dealing with filenames containing globbing characters like *

Solution 4:

I use this always:

# retrieve the inode number
sav@ubuntu:~$ ls -il
total 8
415984 -rw-rw-r-- 1 sav sav    0 Apr 11 10:07 '"la*'
417981 drwxrwxr-x 2 sav sav 4096 Apr 11 09:44  ]rf
415985 -rw-rw-r-- 1 sav sav   11 Apr  8 16:24  text

# use find/delete
find . -inum 415984 -delete