Linux – Remove a file on Linux using the inode number

inodelinuxunix

If you create a file on UNIX/Linux with special characters, such as touch \"la*, you can't remove it with rm "la*. You have to use the inode number (you can if you add the \ before the name, I know, but you'd have to guess as a user that it was used in the file creation).

I checked the manpage for rm, but there's no mention of the inode number. Doing rm inodenumber doesn't work either.

What is the command for this?

Best Answer

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
[~]$
Related Question