I was moving a file with mv but the operation got interrupted. Now I am left with a file I cannot delete on an external NTFS drive. I was moving it from an ext4.

rm file.to.delete
rm: cannot remove ‘file.to.delete’: No such file or directory

total 234M
234M file.to.delete

I got inum from ...

ls -i


find . -inum 12533 -delete
find: cannot delete `file.to.delete': No such file or directory

What should I do next in order to get rid of this file or this file's entry in the file system?


Update: I connected my external NTFS drive to my Windows computer and was able to delete the file. I reconnected the external NTFS to my raspberry pi but am currently having trouble mounting it.

FINAL UPDATE: I reconnected my external NTFS drive to my Windows computer and checked for errors. It found errors and then automatically repaired them. I then reconnected my external NTFS drive to my raspberry pi and mount -a and it mounted no problems. FIXED! :D.

  • Does the file appear if you ls file.to.delete? You can't fsck a file; that's a tool for checking filesystems. If you think the file is still being held be an open file handle, you can sudo lsof | grep deleted to find the PID holding the file open, and kill that process.
    – DopeGhoti
    Apr 3 '17 at 22:44
  • Where were you moving the file from and to, and are these points on the same filesystem or on two different ones? What filesystem types are they? Are you really sure the file still exists? (Why?)
    – roaima
    Apr 3 '17 at 22:53
  • Ok I edited my question. File is on external ntfs. ls returns normal. I don't understand how to use sudo lsof | grep deleted. It outputs a bunch of stuff.
    – deanresin
    Apr 3 '17 at 22:56
  • Shot in the dark - I assume the name is not 'file.to.delete', so maybe the file name is not exactly what you typed. Try typing the first character and using tab completion to get the file name inserted for you (with escapes as needed!), or running ls | hd to check for non-printing or lookalike characters.
    – John P
    Apr 3 '17 at 22:59
  • I tried deleting by -inum and same result so filename is not a problem.
    – deanresin
    Apr 3 '17 at 23:01

It could be that the filesystem iteself is corrupted, and an fsck is needed. Unfortunately, fsck on Linux (which I assume you're using - correct me if I'm wrong) is probably just a link to the ntfs tool ntfsfix, which is not a greatly useful tool.

In that case, to check, I would recommend using your copy of windows (which again, is an assumption, but there's not many other reasons for using NTFS) and running chkdisk on it.

  • my NTFS external drive is connected to my raspberry-pi. I'll try connecting it to my PC and deleting it or performing a chkdisk on it.
    – deanresin
    May 7 '17 at 19:11
  • I hooked it up to my PC (I can't believe I didn't think of trying that) and tried to delete it and Voila! it deleted with no errors. I will connect it to my rbpi again and see if it worked.
    – deanresin
    May 7 '17 at 19:33
  • Hmm... I am currently unable to mount the drive in raspberry pi.
    – deanresin
    May 7 '17 at 19:49
  • 1
    Ok, so would you like to update the original question with the progress so far, and perhaps provide any debug for the not mounting issue?
    – einonm
    May 7 '17 at 19:51
  • You were right the file system was corrupted. I repaired in Windows and then reconnected to the pi and it worked.
    – deanresin
    May 7 '17 at 20:14

Did you try to remove it forecfully ? Try this option if your filename is correct :

rm -rf file.to.delete
  • Yes I tried that to no effect.
    – deanresin
    Apr 4 '17 at 6:17
  • 1
    @lgeorget a wrong answer is still an answer. I quite agree that this answer is unlikely to help the OP but it is, nevertheless an answer.
    – terdon
    Apr 4 '17 at 11:16
  • @terdon I flagged it as "not an answer" because given the information the OP has provided in his question, it's clear that he has already tried that. The automatic comment is not quite what I meant.
    – lgeorget
    Apr 4 '17 at 11:21
  • 1
    I apologize for that answer. I am new to the community, and I couldn't see that he has already used that option. Apr 4 '17 at 11:25
  • @AyushGoyal No worries. :-) and welcome to StackExchange!
    – lgeorget
    Apr 4 '17 at 11:33

Try my answer to a similar question: Cannot rm file because it doesn't exist?

echo "Some Text" > file.to.delete && rm file.to.delete

Please use auto-completion for filename when typing the command in your shell.

  • Can you please add the output from ls file.to.delete | hexdump -C to your question so that possible 8bit characters are visible?
    – Michael
    Apr 4 '17 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.