fdisk Linux Command
Manipulates disk partition table (create, delete, resize partitions).
What does fdisk do?
Manipulates disk partition table (create, delete, resize partitions).
Syntax
fdisk [options] devicePractical example
sudo fdisk -lQuestions about fdisk
How do I list all partitions?
Use `sudo fdisk -l` to list all disk partitions and their sizes. Use `sudo fdisk -l /dev/sda` for a specific disk.
How do I create a new partition?
Use `sudo fdisk /dev/sdb` then press `n` to create a new partition. Follow the prompts to set size and type.
How do I delete a partition?
Use `sudo fdisk /dev/sdb` then press `d` to delete a partition. Select the partition number to delete.
How do I see partition table of a disk?
Use `sudo fdisk -l /dev/sda` to display the partition table including partition types, sizes, and sectors.
What is the difference between fdisk and parted?
fdisk works with MBR partition tables (max 2TB). parted supports both MBR and GPT and can handle larger disks.
How do I change partition type?
Use `sudo fdisk /dev/sdb` then press `t` to change the partition type. Enter the hex code for the desired type.
How do I write changes with fdisk?
Use `w` to write changes and exit. Use `q` to quit without saving. Always double-check before writing.
How do I see disk info without root?
Use `lsblk` or `lsblk -f` to see disk and partition information without needing root privileges.
Related Disk Commands
duEstimates file and directory space usage (disk usage).
mountMounts a filesystem (attaches a device to the directory tree).
dfReports disk space usage for all mounted filesystems (human-readable with -h).
umountUnmounts a filesystem (detaches a mounted device from the directory tree).
ncduInteractive disk usage analyzer with a terminal UI (ncurses-based).
mkfsCreates a filesystem (formats) on a disk partition.