O'Reilly logo

Practical Linux by Bill Ball, John Ray, Michael Turner, M. Drew Streib

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Manipulating Partitions with the sfdisk Command

You can also manipulate your hard drive partitions from the command line (or within scripts) using the sfdisk command. As an example to list all the partitions on your system, type the following:

# sfdisk -l

The resulting output displays onscreen:

/dev/sda1          0+     15      16-   128488+  82  Linux swap
/dev/sda2   *     16     260     245   1967962+  83  Linux native
/dev/sda3          0       -       0         0    0  Empty
/dev/sda4          0       -       0         0    0  Empty

If you ever need the size of a partition you can use sfdisk with the -s option followed by the partition. If you don't give it a partition name, it will tell you the size of all the partitions.

# sfdisk -s
/dev/hda:   6342840
total: 6342840 blocks

sfdisk can also be used to make changes to the partition table ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required