Diskpart clean equivalent command in macOS

Andy

Administrator
Creative Team
User ID
1
Joined
7 Jan 2019
Messages
1,121
Reaction score
57
Points
48
For Windows power users, we all know that diskpart clean command is pretty handy.

To remove all partitions from the disk and make the disk brand new again, in macOS we can use this command:
Bash:
andy-mac:~ andy$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *256.1 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk3         255.9 GB   disk0s2

/dev/disk1 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                 Apple_APFS Container disk2         999.9 GB   disk1s2

/dev/disk2 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +999.9 GB   disk2
                                 Physical Store disk1s2
   1:                APFS Volume Secondary HD            718.5 GB   disk2s1

/dev/disk3 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +255.9 GB   disk3
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD            183.7 GB   disk3s1
   2:                APFS Volume Preboot                 60.1 MB    disk3s2
   3:                APFS Volume Recovery                1.0 GB     disk3s3
   4:                APFS Volume VM                      14.0 GB    disk3s4

/dev/disk4 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk4
   1:                        EFI EFI                     209.7 MB   disk4s1
   2:                  Apple_HFS Seagate Expansion Media 499.8 GB   disk4s2

andy-mac:~ andy$

Select the target disk, for instance if we want to wipe the external drive /dev/disk4, run the following command:
Bash:
bash-3.2# dd if=/dev/zero of=/dev/disk4 bs=1m count=1
1+0 records in
1+0 records out
1048576 bytes transferred in 0.005399 secs (194217112 bytes/sec)
bash-3.2#

Tips: If it's showing disk or resource is busy, use the umount /dev/disk0 command to unmount the disk from the system.

Then the drive will be cleaned and if you go to Mac Disk Utility, the drive will become uninitialised, just like a brand new hard drive that never been used before.
 
Criei uma conta aqui só para agradecer você. Muito obrigado, ja estava quase desistindo de recuperar meu pendrive e sua postagem me salvou.
 
I created an account here just to thank you. Thank you very much, I was almost giving up recovering my pendrive and your post saved me.
You're welcome. I'm glad that your pendrive has now recovered! Cheers 🍻
 
 Short URL:
Back
Top