Format USB Drive from Command Line

Updated 30-Jan-2022

To format a USB drive from the Linux command line, we use the following commands:

  • df - disk free
  • umount - unmount filesystems, see also the mount command
  • mkfs - make filesystem
  • lsblk - list block devices

df command to display drives

df -h

Identify the USB drive to format

umount command to unmount the USB drive

sudo umount /dev/sdb1

Ensure that the correct path to the USB drive, it may be different than /dev/sdb1

Format the USB drive

sudo mkfs.vfat /dev/sdb1

Note that other file systems than vfat may be used, as needed, such as ntfs or ext4

List block devices (to see drive and file system format)

lsblk -f