Delete files by inode number

An inode identifies a file and its attributes including size, owner, permissions, etc. Inode number is unique within a file system, to be specified, we can also call it partition.
Normaly, we use rm to delete files, is there any necessary to remove files by inode? I’d say yes there is!
On the common linux filesystem ext3, it’s allowed to use control characters or characters which are unable to be input on a keyboard or special character such as ^, /, ?, * as a file name.
When using rm, it’s not so convinent to delete these files, and mostly it’s problematic to find out an solution. Using following commands to delete the files are really effective and easy:

Please keep note that the following commands also work on Solaris, FreeBSD and any other Unix-linux-like operation systems:

First find out file inode number with any one of the following command:

stat file-name OR ls -il file-name

If you cannot type the file name, just use * instead of file-name.
Use find command as follows to find and remove a specified file:

find . -inum [inode-number] -exec rm -i {} \;

When prompted for confirmation, press Y to confirm removal of the file.

If you have filename like name “2009/03/21″ then no UNIX/Linux command can delete this file by name. The only way to delete such file is to delete it by inode number.
Linux or UNIX never allows creating filename like 2009/03/21 but if you are using NFS from MAC OS or Windows then it is possible to create such file too.

Tags: ,


Joseph chen is a system administrator from south China. He has a keen interest in Open Source and system administration solutions.

12 Responses to “Delete files by inode number”

  1. Ederirjt says:

    Very interesting site. Hope it will always be alive!,

  2. nice work says:

    Great. Now i can say thank you

  3. ToossyseEslop says:

    Other variant is possible also

  4. goodjob says:

    Thank you very much
    but the remove command is to be
    find . -inum [inode number] -exec rm -i {} ;
    add a ” at the end on linux

  5. goodjob says:

    oh we can’t see back-slant here
    I’m so sorrry

  6. joseph says:

    @goodjob.. Oops, I’m feeling sorry for this issue. Without back-slant, this command is really problematic. I’d pay more attention next time..

  7. Jesse says:

    Keep up the good work, and post more articles like the one you have posted above.

  8. グッチ メンズ says:

    Howdy just wanted to give you a quick heads up. The text in your post seem to be running off
    the screen in Chrome. I’m not sure if this is a format issue or something to do with internet browser compatibility but I thought I’d post to let you know. The design and style look great though! Hope you get the issue solved soon. Many thanks

  9. joseph says:

    Oh That’s cool, thank you!

  10. hog helicopter says:

    Hello to every one, since I am truly keen of reading
    this web site’s post to be updated regularly. It contains pleasant material.

  11. […] Example 6: List inode for each files When you have the inode of a file, it gives you more ability to operate it. E.g. you can delete a file by its inode. […]

  12. Community says:

    If some one needs expert view on the topic
    of blogging afterward i propose him/her to pay a visit this web site, Keep up the fastidious job.

Leave a Reply

© 2006-2009 Admon Linux. All rights reserved.
Powered by Linode Japan