4

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


ls
total 234M
234M file.to.delete

I got inum from ...

ls -i

then

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?

Thanks

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.

deanresin
  • 432
  • 1
  • 5
  • 22
  • 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 03 '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 03 '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 03 '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 03 '17 at 22:59
  • I tried deleting by -inum and same result so filename is not a problem. – deanresin Apr 03 '17 at 23:01
  • @deanresin How did you get the inode number? – Sparhawk Apr 04 '17 at 04:55
  • from `ls -i`. my edit reflects that now. – deanresin Apr 04 '17 at 05:00
  • Is there any debug from the mount failure? If not, you can check /var/log/messages. –  May 07 '17 at 20:01
  • it seems it can't find the UUID of the external drive – deanresin May 07 '17 at 20:02
  • @deanresin Does the info in https://raspberrypi.stackexchange.com/questions/14620/how-do-i-mount-the-correct-drive-everytime-the-raspberry-pi-reboots help? –  May 07 '17 at 20:06

3 Answers3

1

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 07 '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 07 '17 at 19:33
  • Hmm... I am currently unable to mount the drive in raspberry pi. – deanresin May 07 '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? –  May 07 '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 07 '17 at 20:14
0

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

rm -rf file.to.delete
Ayush Goyal
  • 584
  • 2
  • 5
  • 10
  • Yes I tried that to no effect. – deanresin Apr 04 '17 at 06: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 04 '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 04 '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. – Ayush Goyal Apr 04 '17 at 11:25
  • @AyushGoyal No worries. :-) and welcome to StackExchange! – lgeorget Apr 04 '17 at 11:33
0

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.

Michael
  • 39
  • 4
  • 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 04 '17 at 06:36