Mac OS X: Destroy all partitions in USB pendrive

PHOTO EMBED

Mon Aug 29 2022 17:16:03 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero #bash

#--> first identify your USB disk:

fdisk list

# --> Example OUTPUT
: '
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         1.0 TB     disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +1.0 TB     disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD - Datos    907.8 GB   disk1s1
   2:                APFS Volume Preboot                 81.5 MB    disk1s2
   3:                APFS Volume Recovery                526.6 MB   disk1s3
   4:                APFS Volume VM                      2.1 GB     disk1s4
   5:                APFS Volume Macintosh HD            11.0 GB    disk1s5

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                        *248.7 GB   disk2
   1:        Apple_partition_map                         4.1 KB     disk2s1
   2:                  Apple_HFS                         4.1 MB     disk2s2
'

#--> in this example USB stick is disk2 (external, physical):

# --> let's blank complete pendrive:

sudo dd if=/dev/zero of=/dev/disk2 count=1 bs=4096

# --> let's check again:

diskutil list

: '
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                 Apple_APFS Container disk1         1.0 TB     disk0s2

/dev/disk1 (synthesized):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      APFS Container Scheme -                      +1.0 TB     disk1
                                 Physical Store disk0s2
   1:                APFS Volume Macintosh HD - Datos    907.8 GB   disk1s1
   2:                APFS Volume Preboot                 81.5 MB    disk1s2
   3:                APFS Volume Recovery                526.6 MB   disk1s3
   4:                APFS Volume VM                      2.1 GB     disk1s4
   5:                APFS Volume Macintosh HD            11.0 GB    disk1s5

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                                                   *248.7 GB   disk2
'

# Then you can run disk utility to initialize / format pendrive.
content_copyCOPY

You can do this procedure when pendrive results unreadable or when it is not possible to access pendrive from macosx. This will delete all partitions (and all information) but you will restore access to your pendrive.