You don't need to erase the old data first. But you can if you want to. Sometimes it's a good idea. Particularly if you're giving it to someone.
This should do the trick:
Linux:
dd if=/dev/zero of=/dev/sdx
Macintosh:
dd if=/dev/zero of=/dev/diskx
diskutil zeroDisk /dev/diskx
Where sdx or diskx is the target disk. Usually, sda/disk0 is the first disk, containing the main OS, etc. (i.e. SCSI/SATA Disk A), followed by sdb/disk1, sdc/disk2, and so on.
If you have one internal disk (/dev/sda or /dev/disk0), and you connect an external drive via USB; the external drive will be /dev/sdb or /dev/disk1. You get the idea. SD cards are designated names like /dev/mmcblk0 and so on, in a similar fashion.
Some refer to this as zeroing or low-level formatting. The pseudo-file /dev/zero can be thought of as being similar to /dev/null; but designed to be read from, rather than written to. It will supply a steady stream of ASCII NUL (0x00) bytes to whatever process tries to read from it.
The original filesystem will be overwritten.
Some additional options that people commonly like to use with dd, to manipulate block size & data read/write speeds follow the syntax:
bs=512kB count=1
Also, I personally like to have a running status/progress report so I can tell what's going on; to do this, just add the following to the tail end of the command:
status=progress
Take care to specify the correct disk. Especially if copying/pasting commands like this directly into a shell. It takes milliseconds to bork the wrong partition table. To list your storage devices, begin with:
Linux:
lsblk
Macintosh:
diskutil list
The output will look something like this:
/dev/disk0 (internal, physical): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *500.3 GB disk0 1: EFI EFI 209.7 MB disk0s1 2: Apple_HFS Macintosh HD 499.4 GB disk0s2 3: Apple_Boot Recovery HD 650.0 MB disk0s3