System and processes
The fdisk command
Shows and edits a disk's partition table. With -l it only lists.
Most useful options
-l, --listLists the partition tables of the given devices and exits. Without a device it uses those in /proc/partitions-x, --list-detailsLike -l, but with more detail for each partition-o, --output <columnas>Chooses the columns to show. With +column adds one to the default ones-u, --units [=unidad]Shows sizes in sectors (default) or in cylinders. Write it attached: -u=cylinders-t, --type <tipo>Enables only the given table type and disables the others. It also decides the type when a new table is created-n, --noauto-ptDoes not create a default partition table on an empty device; you have to create it yourself-w, --wipe <cuándo>Wipes filesystem or RAID signatures before creating a table. By default (auto) it only does so in interactive modeCopy-ready examples
$ sudo fdisk -lpartition tables of every disk the system sees. It changes nothing.$ sudo fdisk -l /dev/sdathe table of one specific disk.$ sudo fdisk -x /dev/sdathe same table, with more detail for each partition.$ sudo fdisk -u=cylinders -l /dev/sdasizes expressed in cylinders instead of sectors.$ sudo fdisk /dev/sdaWARNING: opens interactive mode on the disk. It is only safe if you just look; any change you confirm can erase partitions and data. First confirm the name with lsblk.You can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- The -l output is meant for people and its format is not guaranteed across versions. For scripts, use lsblk with -o or partx, which the manual points to for that purpose.
- Without -l, fdisk opens interactive mode; on an empty disk it may create a default table. The -n option prevents that.
- Sizes given with +/- are aligned to the device properties, so they do not always match what you typed.
- Editing partitions can destroy data: do not do it on a disk in use without a backup.
Differences from similar commands
- lsblk: shows disks and partitions as a tree, without editing them. fdisk can also change the table.
- parted: another partitioning tool, with different commands and options. Do not mix its commands with fdisk's.
partx: reads and presents partitions with scripts in mind. fdisk is meant to be used by a person.mkfs.ext4: formats a partition that already exists. fdisk only works on the table and does not format anything.
Security
Editing the partition table of a disk in use can leave all its data inaccessible. Use -l to look and make a backup before changing anything.
FAQ
fdisk or parted?
Both can partition a disk. fdisk is the classic one from util-linux; parted has a different interface and different options. Pick one and do not mix their changes on the same disk.
How do I look at disks without changing anything?
With sudo fdisk -l, which only lists. Without -l, fdisk enters interactive mode, and that is where something can be changed.
What does the -w option do?
It wipes filesystem or RAID signatures before creating a table. By default it only does so in interactive mode, but it always warns about the signatures it finds.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course