To protect your privacy, it is always a good practice to securely wipe any data from your unused hard disks and USB drives in case you lose them, or get stolen, or if you simply wish to give them to someone else.
Deleting your files or formatting is not enough, since when you delete a file, while it is removed from the filesystem index and the storage space is reclaimed, the data itself is not actually destroyed. Unless the data have been overwritten, one could easily recover them by using undelete utilities.
To securely erase your data you’ll have to use a specialized program, like GNU shred, which will overwrite your data with multiple patterns or zeros.
Before using shred you need to find out the name of your device. If your device is a USB disk, the name might be something like
/dev/sdc. You can use GNOME Disks for that purpose, which comes pre-installed in Ubuntu.
or, if you prefer the
$ sudo fdisk -l Disk /dev/sdc: 7.55 GiB, 8103395328 bytes, 15826944 sectors Disk model: Transcend 8GB Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x592e48e1 Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 15826943 15824896 7.5G c W95 FAT32 (LBA)
After finding your device name, you can run shred with:
$ sudo shred -vz -n2 /dev/sdc
The above command will overwrite everything on your device with random data, 2 times (
-n2), and then it will set all bits to zero (
-z). Depending on the size of your drive, this might take a while to complete, so be patient.
Keep in mind that everything on your device will be erased, including your partition table, so you will need to create new partitions before using the drive again.
You can read more about the shred command here.