0

How to format pen drive in ubuntu via command line with sudo.

muru
  • 197,895
  • 55
  • 485
  • 740

1 Answers1

2

Erase all data, and create a single partition that takes up all USB with an ext4 filesystem:

printf 'o\nn\np\n1\n\n\nw\n' | sudo fdisk /dev/sdX
sudo mkfs.ext4 /dev/sdX1

Choose X based on the output of:

sudo lsblk
sudo fdisk -l

fdisk automation explained at: https://superuser.com/questions/332252/creating-and-formating-a-partition-using-a-bash-script

Akshay Patil
  • 320
  • 1
  • 4
  • 10