The Computer Oracle

Remove a file on Linux using the inode number

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Magic Ocean Looping

--

Chapters
00:00 Remove A File On Linux Using The Inode Number
00:34 Answer 1 Score 5
00:53 Answer 2 Score 5
01:40 Accepted Answer Score 31
02:03 Answer 4 Score 3
02:10 Thank you

--

Full question
https://superuser.com/questions/143125/r...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #unix #inode

#avk47



ACCEPTED ANSWER

Score 31


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



ANSWER 2

Score 5


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.




ANSWER 3

Score 5


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 *




ANSWER 4

Score 3


You can delete files starting with a dash by calling rm -- filename.