Format disk via terminal in macOS

First, we list the available devices

We use the follow command in our terminal:

diskutil list

And we'll get something like this:

/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     314.6 MB   disk0s1
   2:                 Apple_APFS Container disk1         500.0 GB   disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +500.0 GB   disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD - Data     123.8 GB   disk1s1
   2:                APFS Volume Preboot                 82.5 MB    disk1s2
   3:                APFS Volume Recovery                528.8 MB   disk1s3
   4:                APFS Volume VM                      1.1 GB     disk1s4
   5:                APFS Volume Macintosh HD            11.2 GB    disk1s5

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *30.9 GB    disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:       Microsoft Basic Data LINUXPEN                30.7 GB    disk2s2

In my case, /dev/disk2 is my removable storage, the USB key I will use to showcase the tool.

The actual work

Make sure that you have located the proper ID for the device you want to flash, there's no going back from here.

Once that's done, we use diskutil with the eraseDisk functionality like this:

diskutil eraseDisk FILESYSTEM DEVICENAME /it/myDisk

where:

In my case, the final command looks like this:

diskutil eraseDisk FAT32 LINUXPEN /dev/disk2

The end

After some good ASCII progress bars and other fanciness, the device will be ready!