Ben Chuanlong Du's Blog

It is never too late to learn.

Command Line Tools for Mac File System

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Note: When work both in Linux and macOS, a painful burden to use command-line is to remember subtle differences between Linux commands and macOS commands. A a matter of fact, GNU tools can be used in macOS and it is suggested that you use GNU tools (instead of the macOS version of tools) so that you can have unified command-line experience across operations systems. Please refer to Install GNU Utils Using Homebrew on how to install GNU tools on macOS and Command Line Tools for Linux File System on Linux commands.

If you insist on using the macOS version of tools, continue to read the content below.

  1. Notice that disks in macOS are often named as /dev/diskXsY where X and Y are numbers.

  2. It is suggested that you use the unified command diskutil (instead of scattered commands such as df, newfs_*, etc.) to manage (list, format, partition, etc.) disks in macOS.

    diskutil partitionDisk /dev/diskX 2 MBR \
        ExFAT NewVolumeA 100M \
        ExFAT NewVolumeB R
    diskutil eraseVolume ExFat NewVolume /dev/diskXsY
    
  3. List disk information.

    diskutil list
    
  4. Unmount a volume.

    diskutil unmount /path/to/mounted/volume
    
  5. Management disk partition tables.

    fdisk
    
  6. Format disk partitions.

    newfs_ext4 /dev/sd3 /path_to_mount_in
    newfs_ntfs /dev/sd3 /path_to_mount_in
    newfs_exfat /dev/sd3 /path_to_mount_in
    
  7. Report disk usage.

    du -lhd 1 .
    
  8. dd

    dd
    
  9. badblocks

References

Comments