In this tutorial, we will see various commands that allow you to format your USB disk or pen drive from the Terminal (CLI), no need to use a GUI tool. The commands listed below can be used under Ubuntu or Linux Mint and any other Linux-based platform.

Connect your USB disk to your computer and run this command (root privileges required) to know where it is mounted:

sudo fdisk -l

For my system, I got this output

~$ sudo fdisk -l
Disk /dev/sdb: 7.5 GiB, 8021606400 bytes, 15667200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device     Boot Start      End  Sectors  Size Id Type
/dev/sdb1  *     2048 15667199 15665152  7.5G  7 HPFS/NTFS/exFAT

My USB stick is mounted in /dev/sdb1

To be able to format it, you need to unmount it using this command:

sudo umount /dev/sdb1

List of Commands


You can format your USB disk using mkfs, a command line utility for formatting storage disks. If you want, for example, to format your flash drive in FAT, use this command:

sudo mkfs.vfat -n 'Device_Name' -I /dev/sdb1

For NTFS file system, run this command:

sudo mkfs.ntfs -I /dev/sdb1

For EXT4 file system, run this command:

 mkfs.ext4 -n  -I /dev/sdb1

For other file systems, use the following:
  • ext2
  • ext3
  • msdos    ---> MS-DOS Partition Scheme
  • xfs
  • bfs

You can also use shred command to completely wipe out the whole USB flash drive. Use simply this command:

sudo shred /dev/sdb1

3. DD

DD can also be used to format your drive. Here is the command to use:

sudo dd if=/dev/zero of=/dev/sdb1


sudo dd if=/dev/zero of=/dev/sdb1 bs=1024

Post a Comment