Format USB stick in Ubuntu or any other Linux distro using command line !

Howdy folks.

Formatting or factory reset/format or erase all the content of the external drive is pretty easy when done via GUI tools such as Gparted or Disks in Linux. But what if there are errors shown while formatting etc. We need to hard reset the flash drive anyhow to make it fresh and clean for maybe a new installation of the OS via burning the ISO on to the flash drive or for some other nerdy quests. Now here is the way of doing this via CLI on any Linux distro possible out there.

  • First, you have to find out which device (/dev/sd??) your USB stick is. Become a root user first type
    sudo -i
    fdisk -l
    
  • After that unmount the device/partition (if necessary) by running
    sudo umount /dev/sd**
    

    Make sure you replaced ** (asterisk)with the correct device/partition name from the above output.

  • To format The partition as FAT32 use
    sudo mkdosfs -F 32 -I /dev/sd**
    

    Again replace ** with your respective letters.

Be extremely careful that if you enter the wrong device name, you might also accidentally format your hard disk!

You may also type the below incase you don’t wanna be a root user throughout the process

    sudo -s

[via:- askubuntu forums]