A directory in my external drive contained 1tb data, and when accidentally unplugging, the directory shows empty when opened and in properties...

When I go to delete directory, shows "error: directory not empty"

How to resolve this?

  • What OS are you using? How is the drive formatted? Were you writing anything to the drive when you unplugged it? – Terrance Jul 4 '18 at 14:54
  • Ubuntu, the drive still works so I think it's altrady fat32 formatted (for use over most of systems). I was editing a .ses file created from Photorec... but the editor froze so I force quitted and accidentally unplugged it... no only the specific directory seems to show empty where the see file wad – Ashton Jul 4 '18 at 14:59

You may be able to retrieve a lot of information about your drive when it is connected, and hopefully this will give you some ideas. I will list some command-line based tools.

First thought

rm /direcotry/path -rf

...should solve your problem with this direcotry: it should really remove it for good. If you need to, you can precede the above command with sudo; and you have to be VERY cautious, because you will remove almost anyting you ask it to. Also, type -rf at the end, so if you press Enter accidentally, prematurely, you will not "force" and "recursively" over something you did not intend.

However, if you feel like experimenting more - there is more for you below:

1) Info about ALL disk devices

sudo fdisk -l

...will list device name, size and partitions (and more). In the last column you get the partition type.

I think that fat32 is not the optimal choice for large disks, however, it is fairly standard everywhere. You could use ntfs - nowadays Ubuntu also supports it to some extent.

2) Info about mounted devices

sudo df -h
sudo df -hi

...will pint info about mounted filesystems together with the name of a device that contins it. You have bytes (default) used, you have inodes (specified by -i parameter) which are correlated to the number of files on the disk (not only a size matters, bu also the number of entries in the file allocation table). "h" for human readible units.

cd /directory/path
du -hs

...will let you know the summary of that is in /direcotry/path. "s" for summary rather than a complete list and "h" for human readible units.

du -ms *   | sort -n
du -ms */* | sort -n

...this is the protagon of all console-based disk-free-space checks. My favourite. I love how it shows me the biggest items in the current path. By using asterisk/asterisk instead of asterisk you will compare all sub-items that are in the current location.

ls -lah

...is for viewing the directory too. "h" as above, "a" includes hidden files/dirs, "l" shows access rights and ownership info. Especially "a" flag may be of interest in your case.

3) Still nothing? Format the drive

Copy your precious data elsewhere and format the drive over again. After all, the system might have suffered some damages due to the power loss.

sudo unmount /dev/name0    # carefully select the device

CAREFULLY CHOOSE THE DEVICE. If you make a typo at some point, you may loose all you data and OS, and your machine will stop working.

sudo fsck /dev/name0

...has the potential to repair your disk whis HAS TO BE unmounted. After fsck finishes, you can remount your drive by mount /dev/name0 /any/path/you/want and verify, but sometimes you have to replace the filesystem internals - keep on reading.

sudo mkfs.ntfs /dev/name0

...it overwrites the file system the disk already has. This could also be mkfs.vfat for fat32 or (what I prefer) mkfs.ext3.

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.