I am unable to delete a directory inside my pen drive. The directory is actually empty. When I right click on it and look for its properties, I can just see Contents: nothing. But when I try to delete it from terminal, it says rm: cannot remove 'x': Directory not empty. x is the name of the directory which I wanna delete. I have tried all the following. But nothing has helped me till now.

  • I got a window which read Cannot delete directory when i used shift + del. The window also had an error details option. When I clicked on it, it read Directory not empty

  • As I said earlier, I got a message rm: cannot remove 'x': Directory not empty when I tried deleting it from terminal using the rm -rf x command. And I trying it from my pen drive. So, I hope the path x isn't any issue here

  • I gave it a shot with rm -ir x. Firstly it showed rm: descend into directory 'x'?. I entered y and hit enter. It showed rm: remove directory 'x'?. I confirmed again. It displayed Input/output error

  • I was wanting to get rid of it somehow. So, eventhough I knew that both rm -r x and rn - R x are the same, I made a mad try with rm -R x. It showed the same rm: cannot remove 'x': Directory not empty

  • I tried using rmdir x as I was sure that it had no contents inside it. Yet, it was a failure. It showed rmdir: failed to remove 'x': Directory not empty

Help me delete that strangely behaving directory. Thanks in advance.

  • Sounds as if the pen drive is starting to fail.
    – Panther
    Mar 11, 2015 at 15:56
  • ls -a x may well show a hidden file, which the rm -rf x command should remove. Try sudo rm -rf x? Mar 11, 2015 at 15:56
  • @MarkWilliams: I have tried ls -a x. Even it displayed nothing.
    – Ramvignesh
    Mar 11, 2015 at 16:01
  • @bodhi.zazen: Really a bad news for me :(
    – Ramvignesh
    Mar 11, 2015 at 16:01
  • 1
    It happens with flash drives, back up your data and you can try fsck
    – Panther
    Mar 11, 2015 at 16:10

2 Answers 2


If you encounter such a problem, try like this.

  • right click your directory which disturbs you
  • choose Move to trash so that it is trashed
  • open your Trash
  • click Empty.

Your differently behaving directory will be deleted successfully. This has worked for me.


If it's a pen drive, the file system is most probably FAT or NTFS.

Therefore: Go to a Windows machine and insert the pen drive and execute the following command:


where X is the actual drive letter on that machine.

Then right-click the directory under Windows and Shift+Del it. If that doesn't work either, follow these official Microsoft instructions to take ownership and then Shift+Del it.

If you don't have a Windows machine available, leave a comment below and I'll give you the Ubuntu commands (will only work for FAT, not NTFS)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .