Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · disks & space

fdisk

read and edit the partition table

fdisk 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.

List
fdisk -l
reads only
Edit
fdisk /dev/sdb
interactive
Save
w
q quits without saving
Needs root
Yes
always

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.

root@netflow — bashutil-linux
# fdisk -l /dev/sdb
1Disk /dev/sdb: 14.91 GiB, 16008609792 bytes, 31266816 sectors
Disk model: Flash Drive
Units: sectors of 1 * 512 = 512 bytes
2Disklabel type: dos
 
3Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 31266815 31264768 14.9G c W95 FAT32 (LBA)
4# fdisk /dev/sdb
Command (m for help):
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
The disk itself

Its size and model. Check these against what you expect before going any further.

2
The kind of partition table

dos is the older MBR scheme; gpt is the modern one, needed for disks over 2 TB.

3
One line per partition

Where it starts and ends, its size, and the type recorded for it — here a FAT32 partition filling the stick.

4
The interactive editor

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 -l

Lists the partition tables of every disk.

sudo parted -l

The same information from parted, which some prefer for GPT disks.

sudo mkfs.ext4 /dev/sdb1

Creates a filesystem on a new partition — the step after partitioning.

sudo partprobe /dev/sdb

Asks 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.

Check the device, then check again

fdisk /dev/sda and fdisk /dev/sdb differ by one letter. Compare the size and model shown with lsblk before pressing w.

Deleting a partition does not erase data

It removes only the map. The contents remain on the disk and can be recovered — by you, or by whoever gets the disk next.

Wiping before disposal

To make data unrecoverable a disk must be overwritten or, better, have been encrypted from the start. Repartitioning is not wiping.

Filed under

Disks & space

Read alongside