Formatting a USB Drive Using Terminal

Formatting a USB drive using the Mac Terminal is a fast and efficient way to prepare your drive for use or to erase its contents. The Terminal allows you to format a USB drive with various file systems, including HFS+, APFS, FAT32, and ExFAT.

In this guide, we will walk you through the steps to identify and format your USB drive using Terminal commands.

Step 1: Identify the USB Drive

Before formatting a USB drive, you need to identify its device name. This can be done using the diskutil list command, which lists all the drives connected to your Mac. Open Terminal and run the following command:

diskutil list

The output will display a list of all connected disks, including internal drives and external USB drives. Look for your USB drive by identifying its size and location. It will be listed as something like /dev/disk4 (external, physical). The number may vary. Here’s an example output:

Format USB Drive Using Terminal - First Step to identify the USB

In this example, the USB drive is /dev/disk4.

Step 2: Unmount the USB Drive

Before formatting the drive, you need to unmount it to ensure no data is being accessed. Use the diskutil unmountDisk command followed by the disk identifier. For example:

diskutil unmountDisk /dev/disk4

This will unmount the USB drive, making it safe for formatting.

Format USB Drive Using Terminal - Second Step to Unmount the USB

Step 3: Format the USB Drive

To format the drive, use the diskutil eraseDisk command followed by the format type, a new name for the drive, and the disk identifier. Here are a few common file system formats you can choose:

  • FAT32: Best for compatibility with both Mac and Windows.
  • ExFAT: Best for larger files and compatibility with both Mac and Windows.
  • APFS: Best for Mac-only usage (macOS 10.13 or later).
  • HFS+ (Mac OS Extended): Best for Mac-only usage (older versions of macOS).

To format the USB drive as FAT32 (for use on both Mac and Windows), run the following command:

diskutil eraseDisk FAT32 USB_NAME MBRFormat /dev/disk4
Format USB Drive Using Terminal

To format the USB drive as ExFAT (for larger files and cross-platform compatibility), use:

diskutil eraseDisk ExFAT USB_NAME MBRFormat /dev/disk4

To format the USB drive as APFS (for Mac use only), use:

diskutil eraseDisk APFS USB_NAME /dev/disk4

To format the drive as HFS+ (Mac OS Extended), use:

diskutil eraseDisk HFS+ USB_NAME /dev/disk4

In these commands:

  • USB_NAME is the name you want to give your USB drive.
  • /dev/disk2 is the identifier for your USB drive (replace it with the correct identifier for your device).

Step 4: Verify the Formatting

Once the formatting process is complete, you can verify that the drive has been formatted by running the diskutil list command again. Look for your USB drive in the list and check its format type and name to ensure that everything has been applied correctly.

Format USB Drive Using Terminal - Verification Step