Unable to delete file - no such file or directory

39,325

Solution 1

I know this is old, but I had the same problem as yours, only with a folder, not with a file. None of the methods suggested here worked.

I managed to solve the problem by creating a folder in the same position and with the same name as the one I couldn't delete. The folder was created correctly and it "replaced" the non existing one. Then I simply removed the new folder and the issue was gone. Simple as that.

Solution 2

Warning: These instructions will require one to use debugfs. They can cause data loss.

They are tailored to the original problem and may or may not be accurate for any future visitors on this page. Any data loss may be irreparable or even aggravated by fsck.

It may be a lost inode. Please run ls -li to get a list of inode numbers, then you can try to dump the referenced inode. For example, if your ls -li looks like the following:

rarkenin@ubuntu-alt-64-vbox-1:~$ ls -li
total 58672
4980758 -rwxr-xr-x 2 rarkenin rarkenin     4096 Sep 23 18:45 panorama.jpg
---SNIP---

then the inode number is 4980758 as shown in the list as the first column.

You can then try to dump the inode. Please read the entire post before doing anything.

  1. Start debugfs as root:

    rarkenin@ubuntu-alt-64-vbox-1:~$ sudo debugfs
    [sudo] password for rarkenin: 
    debugfs 1.42 (29-Nov-2011)
    debugfs:  
    

    and give the command open /dev/sda1 with the correct block device for your partition.

  2. Then, give the command to dump the inode whose number you got earlier:

    cat <4980758>
    

    using < and > around the inode number.

  3. If it reads some random text, close the terminal and open it again. Run debugfs again and give the open command again.

  4. Now, you can try to delete the file. This can result in severe filesystem corruption.

    debugfs: rm [filename]
    
    debugfs: unlink [filename]
    
    debugfs: kill_file [filename]
    
    debugfs: kill_file <inode>
    

Note that this can be done even if it turns out the file never had an inode. Try the commands one at a time, in the order shown above. Exit debugfs and check if the file exists. If not, begin again but follow the next instruction.

Make a backup if possible!

Solution 3

I had the same problem. It was a problem in index entries of the partition. I solved it by start Windows if your system is dual boot or insert live CD of Windows XP or Windows 7, and then do the following steps:

  1. Search for COMMAND PROMPT that: is cmd right-click -> Run as administrator.
  2. chkdsk /f/x D: (where D is your drive letter).
  3. Press Y if it asks for Y/N
  4. Check your drive for the file that you want to delete. Maybe it is deleted or you can delete it.

100% working

Share:
39,325

Related videos on Youtube

Valeriu
Author by

Valeriu

Updated on September 18, 2022

Comments

  • Valeriu
    Valeriu almost 2 years

    I deleted it once, but it's ghost is still there :)

    How can I delete a file that is there but the system says is not there?

    Permissions tab - tried changing it, but it would reset itself automatically This is what happens when I click "Delete"

    • Deepak Verma
      Deepak Verma almost 12 years
      This is a warning. What does it say if you choose "Delete"?
    • Eric Carvalho
      Eric Carvalho almost 12 years
      Right click the file, choose Properties, open the Permissions tab. Please take a screenshot and post it here.
    • John S Gruber
      John S Gruber almost 12 years
      Can you move other files to the trash? Is the file you are deleting on the same file system as your home file system? Does the directory ~/.Trash/ exist?
    • Valeriu
      Valeriu almost 12 years
      John, I can move other files to the trash normally, just this one gives me trouble.
    • David M. Sousa
      David M. Sousa almost 12 years
      Did you try to delete it from the terminal? sudo rm panorama.jpg
    • Valeriu
      Valeriu almost 12 years
      Just tried to remove using the terminal - it says cannot remove 'panorama.jpg' - no such file or directory
    • green
      green over 11 years
      Open a terminal. Go to the directory where the file is located. Post the output of ls -l.
    • Valeriu
      Valeriu over 11 years
      @green7 pastebin.com/vjrLdFSR Thanks!
    • green
      green over 11 years
      Okay, so try deleting it with autocomplete. Write rm -rf pa and press Tab so that it autocompletes the name.
    • nanofarad
      nanofarad over 11 years
      I have a feeling it could be a lost inode. Please try ls -li in the directory. Also try stat panorama.jpg.
  • Valeriu
    Valeriu over 11 years
    mywebslave, I did what you suggested, showed me the same 'Permission denied' as in your screenshot. Still can't delete the damn file.
  • Valeriu
    Valeriu over 11 years
    Tried that multiple times, both with -f and --force It did not help!
  • Valeriu
    Valeriu over 11 years
    That's funny! Here's the output: pastebin.com/kjCyX0yB
  • Suici Doga
    Suici Doga about 8 years
    Does not work for my NTFS filesystem
  • nanofarad
    nanofarad about 8 years
    @SuiciDoga debugfs is only intended for ext2, ext3, and ext4 filesystem types.