brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: diskutil activity shows live what happens to disks on your Mac

Disk
~/tips/tip-macos-diskutil-activity

diskutil activity

Shows live when disks appear, mount, unmount or eject on your Mac.

Some disk problems are hard to see because they happen in a flash: a USB drive that mounts and drops away again, or an image that a background app quietly attaches. I like having a live view for those moments, and diskutil has one built in.

diskutil activity keeps printing the disk events that the Disk Arbitration framework reports: disks coming online or being ejected, and volumes being mounted, unmounted or renamed. It runs until you press Control-C:

diskutil activity

Start it in one Terminal window, then plug in a USB stick. You’ll see the new disk appear with its identifier, then its volume being mounted. When a cheap cable or a power-hungry drive makes a disk disconnect and reconnect, you’ll see that too, with every step in order. I’d also use it to find out which identifier a new drive got, before typing something destructive such as an erase command.

It’s just as useful in the other direction. Eject a drive from Finder while it runs, and you can watch whether the unmount and the eject really completed before you pull the cable.

The caveat comes straight from the man page: this output must never be parsed. It’s meant for people watching a terminal, and its format isn’t promised to stay the same. If a script needs to react to disks, the man page points to becoming a Disk Arbitration client; for a simple script, diskutil list -plist and diskutil info -plist give you output that’s built for programs.

Further reading: diskutil man page (SS64 mirror of Apple's man page)

More Disk tips sudo e2freefrag /dev/sdb1 sudo smartctl -a --json /dev/sda | jq '.smart_status.passed' lsscsi -s udisksctl power-off -b /dev/sdX du -sh — .[!.]* * 2>/dev/null | sort -h All Disk tips (44) All topics

Link