Categories: Ubuntu

How to Format a USB on the Ubuntu Terminal

When you have your USB drive, you may want to format it for different reasons such as changing your file system or wiping all the existing data, especially if you want to clean an infected drive. Unlike other operating systems, Linux offers a convenient way of formatting a USB drive graphically and via the command line.

This guide covers the step-by-step process of formatting a USB drive via the command line. We will give the commands to follow while showing an example for demonstration purposes. That way, you can conveniently follow along and format your USB drive.

Step-by-Step Guide to Format a USB on the Ubuntu Terminal

Sponsored

When using Ubuntu, you can quickly format your USB drive with straightforward steps that anyone can get comfortable using. Note that formatting your USB will erase all its contents. If you don’t want to lose any data, create a backup before you start the formatting. Also, ensure that you connected the USB drive to the ports on your computer, then proceed as follows.

First, we must locate where the USB drive is mounted on our Ubuntu. You can use the df command to print all the mounted file systems. Adding the -h option makes the command to print in a human-readable format.

$ df -h

In our case, the target USB drive is the /dev/sdb1 and is in the /media/kyle/k.

Alternatively, you can use the lsblk command and filter the output using the grep command to get the mounted USB drive.

$ lsblk | grep media

Before we format the USB drive, we must unmount it since you can’t format any mounted disk on a Linux system.

To unmount the USB drive, use the umount command followed by the mounted USB drive.

$ sudo umount /dev/sdb1

Once you unmount the USB drive, verify the mounted file systems to verify that we now have the USB drive unmounted.

You are now ready to format your USB drive, depending on the file system that you want to use including FAT32, NTFS, etc.

Sponsored

For FAT32, use the following command:

$ sudo mkfs.vfat /dev/sdb1

For NTFS, use the following command:

$ sudo mkfs.ntfs /dev/sdb1

Use the following command to use the EXT4 file system:

$ sudo mkfs.ext4 /dev/sdb1

In our case, we format the USB drive as FAT32 to make it usable with any operating system.

Your USB drive is now formatted. We can verify it using the fsck command as presented in the following:

$ sudo fsck /dev/sdb1

A formatted USB drive contains no files, like in the previous output, where our /dev/sdb1 displays that it has zero files which confirms that we managed to format it successfully.

You now have your USB drive formatted to use for your activities. If the drive is infected, formatting it cleans up all its clusters, and you now have a clean and usable USB drive.

Conclusion

When you want to format a USB drive on Ubuntu using your terminal, there are different steps that you must follow. First, locate the mounted file system for your USB drive. Next, unmount the USB drive file system and proceed to format it depending on the format file system in your case. Lastly, verify that your USB has been formatted.

Ubuntu Server Admin

Recent Posts

Cut data center energy costs with bare metal automation

Data centers are popping up everywhere. With the rapid growth of AI, cloud services, streaming…

18 hours ago

Build the future of *craft: announcing Starcraft Bounties!

Our commitment to building a thriving open source community is stronger than ever. We believe…

18 hours ago

NodeJS 18 LTS EOL extended from April 2025 to May 2032 on Ubuntu

The clock was ticking: Node.js 18’s upstream End of Life (EOL) The OpenJS Foundation is…

18 hours ago

Native integration now available for Pure Storage and Canonical LXD

June 25th, 2025 – Canonical, the company behind Ubuntu, and Pure Storage, the IT pioneer…

2 days ago

Revolutionizing Web Page Creation: How Structured Content is Slashing Design and Development Time

Co-authored with Julie Muzina A year ago, during our Madrid Engineering Sprint, we challenged ourselves…

3 days ago

Ubuntu Weekly Newsletter Issue 897

Welcome to the Ubuntu Weekly Newsletter, Issue 897 for the week of June 15 –…

3 days ago