To format a SD card (or any other sort of disk you can connect to your Mac) using command line I do as follows:
Open terminal
Hit cmd + space to launch Spotlight, type terminal and hit enter.
Insert SD card
I use my Mac’s SD slot, but it could also be an external USB card reader, an external USB hard disk or whatever.
Identify SD card
In Terminal I type the command:
diskutil list
I might see something like:
/dev/disk0 #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *500.3 GB disk0 1: EFI EFI 209.7 MB disk0s1 2: Apple_CoreStorage 499.4 GB disk0s2 3: Apple_Boot Recovery HD 650.0 MB disk0s3 /dev/disk1 #: TYPE NAME SIZE IDENTIFIER 0: Apple_HFS Macintosh HD *499.0 GB disk1 Logical Volume on disk0s2 0########-####-####-####-########### Unencrypted /dev/disk2 #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *8.0 GB disk2 1: DOS_FAT_32 NO NAME
In this case /dev/disk2 is my SD card.
Format SD card
I format the SD card as FAT32 giving it the name SDCARD using the following command:
sudo diskutil eraseDisk FAT32 SDCARD MBRFormat /dev/disk2
sudo gives me super user rights.
diskutil calls the disk utility program.
eraseDisk is the command for formating.
FAT32 sets the file system.
SDCARD is the to be given name of my choice.
MBRFormat tells the disk utility program to format with a Master Boot Record.
/dev/disk2 is the location of my SD card.
I then am asked for my password. After confirming the formatting is runned.
Verify formatting
To check if the formatting had been successful I use above command again:
diskutil list
I can simply do this by typing the up arrow twice.
Ressources I’ve been using to learn this:
http://michaelcrump.net/the-magical-command-to-get-sdcard-formatted-for-fat32/