fdisk
read and edit the partition tablefdisk works on the partition table — the map at the start of a disk that says where each partition begins and ends. With -l it only lists; opened on a disk it is an editor in which nothing is changed until you write with w.
fdisk -l is safe to run any time. Everything else here can erase a disk.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
Its size and model. Check these against what you expect before going any further.
dos is the older MBR scheme; gpt is the modern one, needed for disks over 2 TB.
Where it starts and ends, its size, and the type recorded for it — here a FAT32 partition filling the stick.
p prints the table, n makes a new partition, d deletes one. Changes stay in memory until w writes them; q leaves without saving.
Switches
A switch changes how the command behaves. These are the ones used day to day; man fdisk lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-l- List partition tables and exit. Changes nothing.
-x- Like -l, with more detail.
-u- Show sizes in sectors.
-w auto- Wipe old filesystem signatures when creating a table.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
sudo fdisk -lLists the partition tables of every disk.
sudo parted -lThe same information from parted, which some prefer for GPT disks.
sudo mkfs.ext4 /dev/sdb1Creates a filesystem on a new partition — the step after partitioning.
sudo partprobe /dev/sdbAsks the kernel to re-read a partition table after it has changed.
In cybersecurity
Editing a partition table is the quickest way to lose everything on a disk.
fdisk /dev/sda and fdisk /dev/sdb differ by one letter. Compare the size and model shown with lsblk before pressing w.
It removes only the map. The contents remain on the disk and can be recovered — by you, or by whoever gets the disk next.
To make data unrecoverable a disk must be overwritten or, better, have been encrypted from the start. Repartitioning is not wiping.