How to: Linux / UNIX Delete or Remove Files With Inode Number

An inode identifies the file and its attributes such as file size, owner, and so on. A unique inode number within the file system identifies each inode. But, why to delete file by an inode number? Sure, you can use rm command to delete file. Sometime accidentally you creates filename with control characters or characters which are unable to be input on a keyboard or special character such as ?, * ^ etc. Removing such special character filenames can be problem. Use following method to delete a file with strange characters in its name:

Please note that the procedure outlined below works with Solaris, FreeBSD, Linux, or any other Unixish oses out there:

Find out file inode

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

stat {file-name}


ls -il {file-name}

Use find command to remove file:

Use find command as follows to find and remove a file:

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

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

Delete or remove files with inode number

Let us try to delete file using inode number.

(a) Create a hard to delete file name:
$ cd /tmp
$ touch "\+Xy \+\8"
$ ls

(b) Try to remove this file with rm command:
$ rm \+Xy \+\8

(c) Remove file by an inode number, but first find out the file inode number:
$ ls -ilOutput:

781956 drwx------  3 viv viv 4096 2006-01-27 15:05 gconfd-viv
781964 drwx------  2 viv viv 4096 2006-01-27 15:05 keyring-pKracm
782049 srwxr-xr-x  1 viv viv    0 2006-01-27 15:05 mapping-viv
781939 drwx------  2 viv viv 4096 2006-01-27 15:31 orbit-viv
781922 drwx------  2 viv viv 4096 2006-01-27 15:05 ssh-cnaOtj4013
781882 drwx------  2 viv viv 4096 2006-01-27 15:05 ssh-SsCkUW4013
782263 -rw-r--r--  1 viv viv    0 2006-01-27 15:49 \+Xy \+\8

Note: 782263 is inode number.

(d) Use find command to delete file by inode:
Find and remove file using find command, type the command as follows:
$ find . -inum 782263 -exec rm -i {} \;

Note you can also use add \ character before special character in filename to remove it directly so the command would be:
$ rm "\+Xy \+\8"

If you have file like name like name “2005/12/31” then no UNIX or Linux command can delete this file by name. Only method to delete such file is delete file by an inode number. Linux or UNIX never allows creating filename like 2005/12/31 but if you are using NFS from MAC OS or Windows then it is possible to create a such file.

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 54 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
54 comments… add one
  • Anonymous Jan 31, 2006 @ 12:41

    What I’m wondering is:”how to do that on a remote server via ftp?” 🙂

    • venki Dec 25, 2010 @ 23:25

      The special files created as above can be removed by ‘rm’ cmd in my ubuntu 10.04. Probably the rm command is updated for simplicity.

  • 🐧 nixcraft Jan 31, 2006 @ 21:18

    Very easy 🙂 Login to your remote ftp server.


    Goto directory where special character files placed. And type command:

    mdel *

    mdel will ask you if you really wish to delete each file in the directory. Make sure you answer y (for yes) for each file containing the special character that you wish to delete. Hope this helps.

  • Anonymous Feb 2, 2006 @ 15:34

    how about deleting the file using
    rm ./”filename”

    as in this case $ rm “+Xy +8”
    ./+Xy +8: ? (y/n) y

  • Anonymous Feb 2, 2006 @ 15:43

    adding to my previous post there is an instance when your rm “filename” wont work.
    say u created a file –help
    it wont get deleted by using rm “–help”

    so we have to rm ./”–help”

  • Anonymous Apr 7, 2006 @ 17:54

    Anonymous: your tip won’t work if the filename has very weird characters (non-printable characters, that is)

  • calib0rx Sep 12, 2006 @ 10:32

    “Anonymous: your tip won’t work if the filename has very weird characters (non-printable characters, that is)”

    Um, yes it will, did you actually try it? Eg, go in to vi and save a file with :wq [ctrl-v backspace]q[ctrl-v backspace]

    which would look like “^?q^?” and continue. Now you have:

    -rw-r–r– 1 root wheel 0B Sep 12 00:55 ?q?

    Where’s the ^!!!!

    So now with ls -li:

    516 -rw-r–r– 1 root wheel 0 Sep 12 00:55 ?q?


    [root@host ~]# find . -inum 516 -exec rm -i {} ;
    remove ./q? y
    [root@host ~]#

    file is gone.

  • Anonymous Oct 3, 2006 @ 20:43

    To make sure find only finds the files in the correct directory use the -mount switch to prevent it jumping across mount points.

  • Liam Dec 22, 2006 @ 2:04

    This is a simple process:
    root@liam # mkdir ^Hms^?
    root@liam # ls -l
    total 14
    drwxr-xr-x 2 root other 512 Dec 22 12:59ms

    list the directory using octal representation. So you know the control characters in the name.

    root@liam # ls -lb
    total 14
    drwxr-xr-x 2 root other 512 Dec 22 12:59 10ms177

    Now simply rm “Control V””Backspace”ms”Control V””Delete”

    Where Control V is a key combination and Backspace is a key. As is Delete. In the above example 10 is BS (BackSpace) and 177 is Delete.

    Very simple…

  • William Sep 13, 2007 @ 22:51

    I have a directory structure:

    # ls -ila
    total 20
    2179132 drwxrwsr-x 2 www www 16384 2007-09-14 00:16 .
    2081399 drwxrwsr-x 101 www www 4096 2007-06-27 14:32 ..
    ? ?——— ? ? ? ? ? 1a6b29c00be.jar

    the last entry couldn’t remove (fsck.ext3 /dev/sd12, rm -f, rm -rf to parent dir, stb…), because no inode. I no idea how to remove it, only found format the partition 🙁

  • FiNeX Oct 26, 2007 @ 11:40

    William, I’ve your problem too:

    ls -lia
    total 40
    14663798 drwxr-xr-x 2 1001 1001 36864 2007-10-26 13:27 .
    14663789 drwxr-xr-x 3 1001 1001 4096 2007-10-26 13:27 ..
    ? ?——— ? ? ? ? ? PROVA D’ABILIT? FF8.htm
    ? ?——— ? ? ? ? ? Prova d’abilit? ff9.htm

    I can’t format the partition! There is more than 100Gb of backup file in it!!!!

    someone have some further suggestions?

  • rubberband Dec 20, 2007 @ 18:45

    I was able to remove a weird file name with unlink in Linux.
    I just inputted:
    unlink ‘weird file !@#$%&.txt’

  • Markus Apr 3, 2008 @ 5:26

    other way to remove files: try e2fsprogs
    it is working on hardly not removing files with wrong attributes

    open -w /dev/…
    rm File

    be carefull!

  • bd May 8, 2008 @ 15:14

    Desi Style. Move all others which you can delete to a different folder.
    Then rm -rf * & restore all those back

  • Balakumar Jun 26, 2008 @ 6:44

    It is very useful command to delete files which contain special Characters..

  • franklin Aug 4, 2008 @ 10:11

    what is rootkit

  • Les Aug 27, 2008 @ 1:20

    Thanks, that worked very well!

  • newel Sep 19, 2008 @ 9:57

    how about if removing a directory with special character with a file within it?

  • MindGrill Dec 19, 2008 @ 10:58


    I am trying to delete a file with inode number in hp ux but it is not prompting anything neither it is deleting teh file?
    what can be the problem??


  • lotr Jan 20, 2009 @ 8:52

    So now the other way around, I want to put back in the directory structure file that is still used by some process (inode is hnown from the /proc//fd).

  • Zimx Feb 18, 2009 @ 7:13

    Hi All,

    permission all files are: -rwxrw-rw-

    I have 23982 total of files, I am triying to remove all of it but I alwasy got this error: “Permission denied”

    what I have tried:
    tried to change the permission on single file
    chmod 777 filename
    chmod: WARNING: can’t access 777
    chmod: ERROR: invalid mode
    (not working)

    chown to my id (not working)

    rm using inode (same error: Permission denied)

    rm using wildcard (not working)

    mv some files or single file to other directory (not working: Persmissin denied)

    please help me to remove this junk files…


    • Adnan Mar 13, 2015 @ 5:57

      thanks 🙂

  • Y Rodrigues Mar 6, 2009 @ 20:45

    I have a file called winhelp.exe16. I can not delete it, neither by your method!
    I am from Brazil, “Operação não permitida” means “Operation not allowed”.

    [yr@localhost dlls]$ ls -l winhelp*
    —–w—- 1 root 32784 98320 Jan 4 1970 winhelp.exe16
    [yr@localhost dlls]$ stat winhelp*
    File: `winhelp.exe16′
    Size: 98320 Blocks: 16 IO Block: 4096 arquivo comum
    Device: 308h/776d Inode: 289 Links: 1
    Access: (0020/—–w—-) Uid: ( 0/ root) Gid: (32784/ UNKNOWN)
    Access: 1970-01-02 18:30:56.000000000 -0300
    Modify: 1970-01-04 06:55:28.000000000 -0300
    Change: 1970-01-03 12:43:12.000000000 -0300
    [yr@localhost dlls]$ find . -inum 289 -exec rm -i {} ;
    rm: remove write-protected arquivo comum `./winhelp.exe16′? y
    rm: imposível remover `./winhelp.exe16′: Operação não permitida
    [yr@localhost dlls]$ su
    [root@localhost dlls]# find . -inum 289 -exec rm -i {} ;
    rm: remove write-protected arquivo comum `./winhelp.exe16′? y
    rm: imposível remover `./winhelp.exe16′: Operação não permitida
    [root@localhost dlls]#

  • Y Rodrigues Mar 6, 2009 @ 22:09

    Hi, people,

    I got a way to delete this file. I ‘ve used debugfs. It has a rm command like the shell. Easy boys, read the man page.

  • ciccio Apr 2, 2009 @ 18:24

    normal people use rm — \+Xy \+\8 , and that’s it 🙂

  • ciccio Apr 2, 2009 @ 18:25

    that long line is a double middle dash : rm “double dash” etc..

  • thiru Jul 7, 2009 @ 7:22

    Hi friend,

    Can any one teach me or tell me how to do backup using tape drive. currently i using “tar cMvf /dev/st0 /home” but not very sure on this. how to do complete backup for few directory using 1 command.



  • farnaz Jul 12, 2009 @ 14:57

    How can I delete a picture in Linux?

  • Dave K Sep 3, 2009 @ 16:41

    Guys, for most cases you can just cd into another dir and do rm ../”-rf-file” and it works a charm. Only prob I had which brought me here was a file name “^M”
    don’t ask how I got it but i could not delete it to save my life…

  • netors Sep 21, 2009 @ 14:53

    I have a server with a web app,
    my inodes are all used up,
    i see this tutorial to delete inodes,
    but, i do not know which inodes/files to delete
    i dont know where my web app is creating this innodes… how can i know this?’

  • 2GB Sep 30, 2009 @ 14:42

    got a 2gb+ file which refuses to delete because of file system does not like large files. sco openserver unix.

    my question is: can i delete it using the inode thing. i don’t want to risk it by trying it before i know the concequences!.

    Thanks for yor help

  • Anonymous Apr 21, 2010 @ 15:44

    Had all kinds of fun trying to remove a file called ????
    Confirmed afterwards that it wasn’t just any old
    # touch “????”
    … kind of file. Simple “” did the trick on that one. But the original file (don’t know how it was created) wouldn’t go down with rm with any manner of escaping, find (inode and -exec rm, method), or debugfs’s rm command. Eventually booted up Windows–pains me to say it, but…. WinSCP saw it as four ASCII squares and was able to delete it. (WinSCP saw the `touch “????”` file properly… as ????)

  • Mohit Joshi May 14, 2010 @ 16:34

    how can we describe the uses of inode in linux ?

  • cienias Jun 24, 2010 @ 11:32

    thx man 🙂

  • Anonymous Aug 24, 2010 @ 22:20

    This will delete a file regardless of how screwed up the name is. Copy ‘del’ to somewhere in your path, run del . Paste the following into a file (del.c) and run cc -o del del.c


    main(int argc, char **argv)
    return remove(argv[1]);

  • Madhukar Nov 11, 2010 @ 6:46

    one file got renamed to noname file (blank). Is it possible to open or rename a file with tab in its name.

    apprieciate any help regarding this.

  • Dean Apr 19, 2011 @ 14:05

    Thanks – very useful.


  • Sanjay Kumar Jul 6, 2011 @ 18:32

    I got a better idea to delete/rename files/folder with special character and also without any risk..
    Just WINSCP from Windows system to UNIX/Linux system.. then you can search and rename/delete the file/folder

    • safwan Nov 4, 2012 @ 11:01

      Awesome tip. I also ftp into my vps and deleted the whole directory without any problem. I was unable to delete the directory with inode number

  • Anonymous Jul 11, 2011 @ 12:57

    On a related note,
    using find {args} -exec rm -rf {} ;
    is deprecated and should be replaced with find {args} -delete

  • Jack Nichol Aug 4, 2011 @ 8:36

    In my server i can see that the Inode is full. It shows 100%. It cause error when i access my domain in the browser. I have cleared all the files in “/tmp”. Now i have few free space in Inode.

    [~]# df -i
    Filesystem Inodes IUsed IFree IUse% Mounted on
    /dev/sd1 1200000 1188860 12640 100% /
    none 153600 96 153504 1% /dev

    How to find the files which cause the Inode space to be full. Is there any command to find the files that has created in the server due to Inode session. Please help.

  • Ken Oct 18, 2011 @ 21:18

    I have an inode with 2 duplicate blocks. I have the name of the inode and the blocks (all numbers) so how can I delete only one block and leave the other?

  • Pradeep Dec 19, 2012 @ 7:40

    I have two directories with the same name.Strange is when i do ls -li , it is not even showing the inodes also.. Now how can i delete one directory?

  • jptschudy Dec 30, 2012 @ 21:50

    $ rm ‘+Xy +8’
    works great on my ubuntu 12.10…

  • Ramesh Apr 19, 2013 @ 10:41

    Delete or remove files or directory with inode number
    Let us try to delete file using inode number.

    #find . -inum -exec rm -ir {} ;

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

  • Ramesh Apr 19, 2013 @ 10:42

    #find . -inum [inode number ]-exec rm -ir {} ;

  • Tobias Jul 9, 2013 @ 9:20

    No need for that if you can do a ls on the file. Even if the file starts with a dash, thus beingt interpreted as an option
    rm — ‘–my-file-with-dash’
    works fine.

    Sometimes there are files called ‘^H^H^H’ or so. You won’t see the name on the console (under some circumstances). One could call
    rm -f — ???
    if there is no file like ‘xyz’ in the console. Here this find command works fine.

    So thanks for that idea!

  • venkat May 5, 2014 @ 14:25

    find . -inum |xargs rm -f

    • venkat May 5, 2014 @ 14:27

      ind . -inum |xargs rm -f

    • venkat May 5, 2014 @ 14:28

      ind . -inum inodenumber |xargs rm -f

  • vivek Nov 11, 2014 @ 13:58

    The above command for removing the file through inode number is not working properly.pls give the solution for it?????

    • Rich M. Dec 16, 2014 @ 15:11

      The command line “find . -inum inodenumber | xargs rm -f”
      Is not passing the proper file name to the rm command. To see this replace “rm -f” with “echo $*” (do not include the quotes). I’m not sure why you’re piping the output to the “xarg” in the first place.

      I suggest you use the “-exec” option of the “find” command:
      find . -inum -exec rm {} ;
      Also, as someone above mentioned, simply use the backslash “” in front of any special characters such as forward slash “/” periods, “.” hash marks “#”, dollar sign “$” etc. The backslash, also called the escape character as it “escapes” the special meaning of the single, following character.

      If there are embedded spaces in the file name then also, surround everything in double quotes. This my experience using US keyboards on US systems, your experience may vary.

  • Adnan Mar 13, 2015 @ 6:00

    Thanks Dear 🙂

  • CleanS7 Apr 4, 2016 @ 10:36

    rm -- '–my-file-with-dash'
    works fine.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum