Formatting USB drive in linux command line is very easy but most of the Linux desktop users are scared to do that and they will go for GUI based application instead of CLI.
Folks don’t worry, i’m here to help you out on this.
You don’t worry anything about it and just follow my instruction to get rid out of it.
It’s very simple compared with GUI but you should understand few things that’s it.
First insert your USB into your system and verify whether your USB disk drive is auto mounted or not on your system.
The below output is clearly showing that my USB is already mounted in my system successfully.
Make a note: Make sure you have to identify the correct USB device because you may format other disks wrongly, if you are not choosing the correct one.
Run the following df -h command to list all mounted devices in your system.
$ df -hFilesystem Size Used Avail Use% Mounted on
dev 7.8G 0 7.8G 0% /dev
run 7.8G 1.7M 7.8G 1% /run
/dev/nvme0n1p1 217G 83G 124G 41% /
tmpfs 7.8G 674M 7.1G 9% /dev/shm
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 7.8G 38M 7.8G 1% /tmp
tmpfs 1.6G 12K 1.6G 1% /run/user/120
tmpfs 1.6G 32K 1.6G 1% /run/user/1000
/dev/sda2 932G 546G 387G 59% /run/media/daygeek/DATA
/dev/sdb 7.5G 1.5G 6.1G 20% /mnt/usb
If it’s mounted successfully, run the following command to view the data that is available on your USB disk.
$ ls -lh /mnt/usbtotal 1.5G
-rwxr-xr-x 1 root root 1.5G Dec 9 07:26 'www.TamilRockers.ci - Ye Mantram Vesave (2018) Telugu Proper 720p HDRip AC3 5.1 x264 1.4GB ESubs.mkv'
Run the following command to view the mount options for your USB disk.
$ mount | grep sdb/dev/sdb on /mnt/usb type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro)
If you successfully identified the USB disk, just run the following command to unmount the disk.
$ sudo umount /dev/sdbOnce you unmounted the device, run the “df -h” command once again to double confirm whether the device is unmounted or not.
$ df -hFilesystem Size Used Avail Use% Mounted on
dev 7.8G 0 7.8G 0% /dev
run 7.8G 1.7M 7.8G 1% /run
/dev/nvme0n1p1 217G 83G 124G 41% /
tmpfs 7.8G 364M 7.4G 5% /dev/shm
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 7.8G 38M 7.8G 1% /tmp
tmpfs 1.6G 12K 1.6G 1% /run/user/120
tmpfs 1.6G 48K 1.6G 1% /run/user/1000
/dev/sda2 932G 546G 387G 59% /run/media/daygeek/DATA
Format the USB drive with FAT filesystem to use the USB in all kind of systems like windows, Linux, etc,.
$ sudo mkfs.vfat /dev/sdbmkfs.fat 4.1 (2017-01-24)
Format the USB drive with NTFS filesystem to use the USB device only in Windows system.
$ sudo mkfs.ntfs /dev/sdbFormat the USB drive with Ext4 filesystem to use the USB device only in Linux system.
$ sudo mkfs.ext4 /dev/sdbFormat the USB drive with XFS filesystem to use the USB device only in Linux system.
$ sudo mkfs.xfs /dev/sdbOnce you format your USB, again mount your USB disk back to verify whether all the data got erased or not.
$ sudo mount /dev/sdb /mnt/usbYes, it’s got erased as i can see only 1% utilization on the disk.
$ df -hFilesystem Size Used Avail Use% Mounted on
dev 7.8G 0 7.8G 0% /dev
run 7.8G 1.7M 7.8G 1% /run
/dev/nvme0n1p1 217G 83G 124G 41% /
tmpfs 7.8G 431M 7.4G 6% /dev/shm
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 7.8G 49M 7.8G 1% /tmp
tmpfs 1.6G 12K 1.6G 1% /run/user/120
tmpfs 1.6G 44K 1.6G 1% /run/user/1000
/dev/sda2 932G 546G 387G 59% /run/media/daygeek/DATA
/dev/sdb 7.5G 4.0K 7.5G 1% /mnt/usb