removing file by inode

S

s99999999s2003

hi
this is pertain to unix environment.
is it possible to remove a file by it's inode and not it's filename
using Python? Just curious...
thanks.
 
A

Arne Ludwig

Good answer. :) I seriously doubt it is possible except for the
trivial solution:

def remove_a_file(inode):
os.system ("find / -inum %d | xargs rm -f" % (inode))

PS. Don't blame me if this function destroys your hard disk. I wrote it
off the top of my head.
 
G

Grant Edwards

Good answer. :) I seriously doubt it is possible except for the
trivial solution: [...]

I don't know if there is a Linux equivalent, but under SunOS
there was a way to delete a file given it's i-node. And that's
all it did was delete the file itself and mark the i-node as
free. It didn't remove any directory entries referring to the
i-node.

It left your filesystem in a rather broken state, so you had to
run fsck afterwards.
 
A

Arne Ludwig

under SunOS there was a way to delete a file given it's i-node.

Yes and no. You probably mean "clri" which cleared the inode, but did
not "remove the file", i.e. all the entries in directories pointing to
it.

In older Unices there was also "ncheck" to find the filesystem names
for inode numbers.

I cannot find either command in Linux.
 
A

Arne Ludwig

Actually under Linux he could probably pipe "clri %d" to debugfs if
that is what he wanted to do. On the other hand he said "unix
environment" which could be anything really.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top