What is the equivalent of the Linux command "sudo fdisk -l" in MacOS?

You can use the 'diskutil' tool for that:

% diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage                         499.2 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                  Apple_HFS Macintosh HD           *498.9 GB   disk1

As far as I remember...

For Mac OS X:

  1. diskutil (manpage) is a command-line tool for everything Mac OS X can handle, i.e. it will provide as much or more than Disk Utility can do graphically.
  2. For MS-DOS MBR (Master Boot Record) partitioned drives, use fdisk (manpage).
  3. For Apple APM (Apple Partition Map) partitioned drives, use pdisk (manpage).
  4. For Apple and (U)EFI GPT (GUID Partition Table) partitioned drives, use gpt (manpage).

If you want a GPT command that is fdisk-like, you should try gdisk "GPT fdisk" from Rod Smith. You can find (important) associated information here and download information here.

For Linux:

Modern Linux uses parted for partitioning, so fdisk may still be around, but you would really want to use parted instead.

  • GNU Parted parted supports all common partition tables, including MBR, APM and GPT. Most Linux distributions have good manuals for the use of parted, i.e. during installation, but I always recommend reading the wikipages from ArchLinux—IMHO they are the best, except that this particular one is currently not very up-to-date (Dec 30 2016)!
  • fdisk is for MBR partitions only. If you try to change the partition table on a GPT partitioned disk, you will instead corrupt the "protective MBR" which is part of the GPT specification. parted will prevent you from doing that!
  • pdisk has been ported from Darwin (the BSD base of Mac OS X) to Linux, so you could also use pdisk to create an APM partition table and manage its partitions. The problem is that modern Linux distributions don't include a precompiled package with pdisk anymore. Status of pdisk
  • mac-fdisk is the way to go on Linux/​PowerPC. Most x86 (and x64) distributions don't include mac-fdisk because it is big-endian only. Looking at Debian you see that only powerpc/​powerpc64 packages are available, except for experimental packages for m68k, but not x86. The only Linux I know of that has a working mac-fdisk on x86/​amd64 is Gentoo Linux.
  • For GPT partitions parted does a great job. If you want an fdisk-like command-line tool, you can use either gpt or gdisk, although there might be more...

To answer your question:

fdisk on macOS (previously OS X, originally Mac OS X) acts just the same, but you should check for the partitioning scheme used:

  1. x86-PCs (16-Bit, 32-Bit "i386" and 64-Bit "x64") with BIOS use(d) Master Partition Record (MBR).
  2. Intel Itanium (IA-64), x86-PCs (IA-32, this includes 64-Bit i.e. amd64 i.e. x64 i.e. x86-64) with UEFI and Intel-Macs, all of them use EFI/​UEFI (Universal Extensible Firmware Interface), use the GUID Partition Table (GPT).
  3. Apple Macintosh running on m86k (Motorola 68000 series of processors) and PowerPC use Apple Partition Map (APM).

This doesn't limit the particular partitioning scheme of external drives, naturally, since all of those computers can use each partitioning scheme on external media if the operating system supports it. But for internal drives, more specifically: boot drives, only the one partitioning scheme can be used.

Therefor: if you use fdisk on a Mac on an internal drive, you will have no luck, since there is no MBR on that drive. It is either APM or GPT. Likewise, if you use fdisk on a modern PC with UEFI (or an Intel Mac with EFI) you will only see the protective MBR of the GPT, not the real partition table.

For creating/​managing partitions, running fdisk on an external drive that uses MBR partitioning will work on macOS like it does on Linux.

For listing existing partitions on macOS (Mac OS X), use sudo diskutil list (see also this great article at OSXDaily.com). On Linux, the equivilant is sudo parted -l, or if you want a specific drive only, sudo parted /dev/sda print.


Simply use fdisk /dev/rdisk0 to get CHS and end block of a partition

LiuJianweis-iMac:~ liujianwei$ sudo fdisk /dev/rdisk0
Password:
Disk: /dev/rdisk0   geometry: 15566/255/63 [250069680 sectors]
Signature: 0xAA55
        Starting       Ending
 : id  cyl  hd sec -  cyl  hd sec [     start -       size]
1: EE 1023 254  63 - 1023 254  63 [         1 -  250069679] <Unknown ID>
2: 00    0   0   0 -    0   0   0 [         0     -      0] unused      
3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
4: 00    0   0   0 -    0   0   0 [         0 -          0] unused