Cheat Sheets

Mac Terminal Commands Cheat Sheet (PDF): System, Disk, Network

Most Mac terminal cheat sheets are Linux cheat sheets in disguise: ls, grep, chmod, top. Those commands run fine on a Mac, but they don’t manage it. Reading the hardware, erasing a disk, changing DNS, keeping a Mac mini awake and restarting a background job all go through Apple’s own tools, and none of them behaves like the Linux command you’d reach for first.

Original content from computingforgeeks.com - post 181468

This mac terminal commands cheat sheet covers those macOS-only tools: system_profiler for hardware info, diskutil for disks and APFS, networksetup and pmset, defaults write, launchctl and mdfind. Every command below was run on macOS 27.0 on an M4 Mac mini with 24 GB in November 2026 (service names and timers adapted to that box), over SSH, so you’ll also see the errors a remote session gets that a desktop session doesn’t. The whole reference is a one-page PDF too.

Mac terminal commands cheat sheet

You’ll find the tables grouped by job, in the same order as the explained sections further down. Commands with sudo change system state and ask for an admin password; the rest run as your normal user. Disk identifiers such as disk8 and service names such as Wi-Fi are examples, so read yours from diskutil list and networksetup -listallnetworkservices before you type anything that writes.

System and hardware info

CommandWhat it does
sw_versmacOS name, version and build number
sw_vers -productVersionVersion number only, for scripts
system_profiler SPHardwareDataTypeModel, chip, cores, memory, serial number
system_profiler SPSoftwareDataTypeOS, kernel, boot volume, SIP state, uptime
system_profiler -listDataTypesEvery report system_profiler can print
sysctl -n machdep.cpu.brand_stringChip name, for example Apple M4
sysctl -n hw.ncpu hw.memsizeCore count and RAM in bytes
uname -marm64 on Apple silicon
scutil --get ComputerNameThe name shown in Sharing settings
csrutil statusSystem Integrity Protection on or off
fdesetup statusFileVault on or off
softwareupdate -lList available macOS and CLT updates

Disks, APFS and snapshots

CommandWhat it does
diskutil listEvery disk, partition and APFS volume
diskutil info /Details of the volume mounted at /
diskutil apfs listAPFS containers and the volumes inside them
diskutil eraseDisk APFS Backup disk8Wipe disk8 as one GPT APFS volume
diskutil eraseDisk ExFAT USB GPT disk8Wipe disk8 as exFAT for Windows and Linux
diskutil unmountDisk disk8Unmount every volume on disk8
diskutil eject disk8Unmount and detach the disk
diskutil verifyVolume /Volumes/BackupCheck a volume for errors (First Aid)
diskutil image create blank --size 512m --volumeName Scratch --fs APFS t.dmgCreate a disk image
diskutil image attach t.dmgMount a disk image (replaces hdiutil attach)
tmutil listlocalsnapshots /Local Time Machine snapshots
sudo tmutil thinlocalsnapshots / 10000000000 4Free about 10 GB of snapshot space now

Networking

CommandWhat it does
ipconfig getifaddr en0IPv4 address of en0
networksetup -listallhardwareportsMap each port to en0, en1 and so on
networksetup -listallnetworkservicesService names other commands expect
networksetup -getinfo Wi-FiIP, subnet, router of a service
networksetup -getdnsservers Wi-FiDNS servers set by hand on a service
sudo networksetup -setdnsservers Wi-Fi 1.1.1.1 9.9.9.9Set DNS servers on a service
sudo networksetup -setdnsservers Wi-Fi EmptyGo back to DHCP-provided DNS
scutil --dnsThe resolver config macOS actually uses
sudo killall -HUP mDNSResponderFlush the DNS cache
route -n get defaultDefault gateway and interface
lsof -nP -iTCP -sTCP:LISTENWhich process listens on which TCP port

Power and sleep

CommandWhat it does
pmset -gActive power settings
pmset -g customSaved settings per power source
pmset -g battBattery percentage and power source
pmset -g assertionsWhich process is blocking sleep
sudo pmset -c sleep 0Never sleep while on the charger
sudo pmset -a displaysleep 15Display off after 15 minutes, all sources
sudo pmset repeat wakeorpoweron MTWRF 08:00:00Wake or power on weekdays at 08:00
pmset -g schedShow scheduled wake and power events
sudo pmset repeat cancelRemove the repeating schedule
caffeinate -i -t 3600Block idle sleep for one hour
caffeinate -dKeep the display awake until Ctrl+C

defaults (hidden settings)

CommandWhat it does
defaults domainsEvery preference domain on the account
defaults read com.apple.dockAll Dock preferences you have set
defaults read-type com.apple.dock autohide-delayType of one key (boolean, integer, float)
defaults write com.apple.finder AppleShowAllFiles -bool trueShow hidden files in Finder
defaults write com.apple.finder ShowPathbar -bool truePath bar at the bottom of Finder
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool trueNo .DS_Store files on network shares
defaults write com.apple.dock autohide-delay -float 0Dock appears with no delay
defaults export com.apple.dock dock-backup.plistBack up a whole domain
defaults delete com.apple.dock autohide-delayRemove a key, back to the default
killall DockRestart the Dock to apply Dock keys

launchd and launchctl

CommandWhat it does
launchctl listJobs in your context: PID, last exit status, label
plutil -lint job.plistCheck a plist for syntax errors
sudo launchctl bootstrap system /Library/LaunchDaemons/com.example.backup.plistLoad a LaunchDaemon
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.example.backup.plistLoad a LaunchAgent (desktop session only)
sudo launchctl print system/com.example.backupFull state of one job
sudo launchctl kickstart -k system/com.example.backupRun or restart a job now
sudo launchctl disable system/com.example.backupKeep a job from loading at boot
sudo launchctl print-disabled systemJobs with an enable or disable override
sudo launchctl bootout system/com.example.backupUnload a LaunchDaemon
launchctl managernameWhich launchd context your shell is in

Spotlight from the shell

CommandWhat it does
mdfind -name invoice 2>/dev/nullFiles whose name contains invoice
mdfind -onlyin ~/Documents "kubernetes upgrade"Content search inside one folder
mdfind 'kMDItemContentType == "com.adobe.pdf"'Every PDF the index knows about
mdls -name kMDItemContentType file.pdfMetadata attributes of one file
mdutil -s /Is indexing enabled on a volume

Desktop-session tools

CommandWhat it does
open .Open the current folder in Finder
open -a TextEdit notes.txtOpen a file with a specific app
pbcopy < id_ed25519.pubCopy a file to the clipboard
pbpaste > notes.txtPaste the clipboard into a file
screencapture -x shot.pngSilent full-screen screenshot

Those tables cover the daily set. Below them, each section explains the commands that trip people up, mostly because they look like a Linux tool and then behave differently, and shows what each one printed on the test Mac. For keyboard work and shell setup there are separate references, the macOS keyboard shortcuts cheat sheet and the guide to Oh My Zsh on macOS.

Hardware info lives in system_profiler

There’s no /proc/cpuinfo, no lscpu and no dmidecode on a Mac. The report you see in System Information is system_profiler, and the shell can ask it for one section at a time instead of the whole dump. That matters for speed and for scripts, because a bare system_profiler runs every report in turn and buries the line you wanted. On macOS 27 there are 51 data types to pick from, and system_profiler -listDataTypes lists them.

For a quick answer, you’ll want the version, the chip and the memory. Ask for all three at once:

sw_vers
sysctl -n machdep.cpu.brand_string hw.ncpu hw.memsize
system_profiler SPHardwareDataType

On the test Mac you get macOS 27.0, build 26A428, an Apple M4 with 10 cores and 25769803776 bytes of memory, which is 24 GB. The serial number and the two hardware IDs are blanked in the capture, since they identify the machine.

Mac terminal hardware info: sw_vers, sysctl and system_profiler SPHardwareDataType on a Mac mini M4 running macOS 27

On Apple silicon the block has a Chip line where Intel Macs printed a processor name and clock speed, so a script that greps for Processor Name returns nothing on an M-series Mac. The lines you’ll usually want are, in order:

  1. Model Identifier: Mac16,10 for this M4 Mac mini
  2. Total Number of Cores: 10, split 4 performance and 6 efficiency
  3. Memory: the unified memory the GPU shares
  4. System Firmware Version: what a macOS update just flashed

Need one value for a script rather than a report? Use sysctl or sw_vers -productVersion, because each prints a single value with no parsing. sw_vers -productVersion printed 27.0 here, which is what an install script should compare against, and uname -m printed arm64. The software report (SPSoftwareDataType) adds the kernel (Darwin 27.0.0), the boot volume, the SIP state and the time since boot.

diskutil addresses disks by identifier

Before any disk change, run diskutil list, because macOS hands out identifiers like disk4 in the order devices appear, not by port. A USB stick that was disk4 yesterday can be disk5 after a reboot, and eraseDisk will not ask which physical drive you meant. The test Mac shows why you should read the whole list.

diskutil list output on macOS 27 showing the internal SSD, synthesized APFS containers and an external boot disk

Each physical disk appears twice: once as the disk with its partitions, and once as a synthesized APFS container holding the volumes. Read the list in this order:

  1. disk0: the internal SSD and its partitions
  2. disk3: the synthesized container on that SSD
  3. its volumes by role: System (named InternalDisk here), Data, Preboot, Recovery, VM
  4. anything marked (external, physical) and its own container

On this machine the catch is the last group. It is an EC2 Mac mini, and it boots from network storage that macOS sees as disk5 (external, physical), so the volume called Macintosh HD sits in disk6, not on the internal SSD. So diskutil list external does not hide your boot disk on every Mac. Anyone booting from a Thunderbolt SSD gets the same layout, so check the volume names and sizes against the drive you plugged in, every time.

Rather than practise on a real drive, you can rehearse an erase on a disk image, which behaves like a USB stick to diskutil. On macOS 27, hdiutil create and attach print a deprecation warning that points at diskutil image (and hdiutil detach points at diskutil eject), so create and attach the image with the new verbs:

diskutil image create blank --size 512m --volumeName Scratch --fs APFS usb-test.dmg
diskutil image attach usb-test.dmg

Attaching prints the device nodes, and the first one (/dev/disk8 here) is the whole disk you erase. Give the format first, then the volume name, then the optional partition scheme, then the identifier.

diskutil eraseDisk ExFAT USB GPT disk8

An erase unmounts the disk, writes a new GPT map and formats the single partition. Once you see Finished erase on disk8, the partition type in diskutil list disk8 changes from Apple_APFS to Microsoft Basic Data, which is how exFAT shows up. The old hdiutil attach still works, as the last command in the capture shows, but it now warns every time:

diskutil image create, diskutil eraseDisk ExFAT on a disk image and the hdiutil attach deprecation warning on macOS 27

Pick exFAT when your drive also has to mount on Windows and Linux, and APFS (diskutil eraseDisk APFS Backup disk8) when it only ever meets Macs. A typo in the identifier fails safely, since disk99 returned Could not find disk for disk99, but a wrong existing number does not. Writing a bootable installer to the stick is a different job, covered in the guide to creating a bootable USB on macOS and Linux.

Disk space that df and Finder disagree about usually lives in APFS snapshots. Time Machine keeps local snapshots on the startup disk, and they count against free space until macOS thins them. To see the cycle end to end, take one, list it and thin it:

sudo tmutil localsnapshot
tmutil listlocalsnapshots /
sudo tmutil thinlocalsnapshots / 10000000000 4

For the thin, you pass the mount point, the bytes to free and an urgency from 1 to 4. On the test Mac it created one snapshot and the thin removed it straight away, because 10 GB was more than the snapshot held.

NOTE: local snapshots are considered purgeable and may be removed at any time by deleted(8).
Created local snapshot with date: 2026-10-31-210628
Snapshots for disk /:
com.apple.TimeMachine.2026-10-31-210628.local
Thinned local snapshots:
com.apple.TimeMachine.2026-10-31-210628.local

One more thing diskutil info / reveals: the root filesystem is not a normal volume. On macOS 27 it reported This disk is an APFS Volume Snapshot, with Sealed: Yes and Volume Read-Only: Yes, so nothing you do in the shell writes to /System. Your files live on the Data volume mounted at /System/Volumes/Data.

networksetup works on services, not interfaces

Linux tools take an interface name. Most networksetup commands take a network service name instead, the label you see in System Settings, such as Wi-Fi or Thunderbolt Ethernet Slot 1. Pass an interface and it refuses, with an error that does not mention services at all.

en4 is not a recognized network service.
** Error: The parameters were not valid.

Get both lists before you change anything. -listallhardwareports maps each port to its device, and -listallnetworkservices prints the names the other commands expect, with an asterisk in front of any disabled one:

networksetup -listallhardwareports
networksetup -listallnetworkservices

Don’t assume en0 is the port carrying traffic. On the test Mac the built-in Ethernet is en0 but its service is disabled (*Ethernet), and the live link is en4, named Thunderbolt Ethernet Slot 1. ipconfig getifaddr en0 printed nothing and exited 1, while route -n get default named en4 straight away. Quote service names with spaces:

networksetup -listallnetworkservices, the en4 is not a recognized network service error and scutil --dns on macOS 27

Setting DNS by hand and then forgetting it is a common cause of a Mac that resolves fine at home and fails on a VPN. Set the servers, check them, then hand DNS back to DHCP with the Empty keyword:

sudo networksetup -setdnsservers "Thunderbolt Ethernet Slot 1" 10.0.0.2 1.1.1.1
networksetup -getdnsservers "Thunderbolt Ethernet Slot 1"
sudo networksetup -setdnsservers "Thunderbolt Ethernet Slot 1" Empty
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

While the manual servers were set, scutil --dns listed both of them under resolver #1. After Empty, -getdnsservers answered There aren't any DNS Servers set on Thunderbolt Ethernet Slot 1., which means DHCP owns DNS again, not that DNS is broken. Use scutil --dns rather than cat /etc/resolv.conf to see what macOS resolves with: the file holds one search domain and one nameserver, while scutil also prints the per-domain mDNS resolvers for .local and the reverse zones, which a resolv.conf can’t express. The ifconfig, ip and DNS details have their own page on the ip and ifconfig commands on macOS.

pmset settings belong to a power source

A pmset setting is not global. Each value is stored per power source, and the flag before the setting picks which one you change:

  • -a all sources
  • -c charger (AC power)
  • -b battery
  • -u UPS

So sudo pmset -c sleep 0 keeps a MacBook awake on the charger and still lets it sleep on battery, which is usually what you want. A desktop Mac only has the AC profile: pmset -g custom on the Mac mini printed a single AC Power: block and pmset -g batt answered Now drawing from 'AC Power'. Read the active values with pmset -g; a sudo pmset -a displaysleep 15 showed up there as displaysleep 15 immediately, with no restart.

Does your Mac refuse to sleep with every timer set? Then the settings are not the cause. Some process holds a power assertion, and pmset names it for you. To see one appear, start a 30-second caffeinate in the background and ask:

caffeinate -i -t 30 &
pmset -g
pmset -g assertions

The sleep line of pmset -g now ends in (sleep prevented by caffeinate, powerd), and the assertions list shows the caffeinate PID holding PreventUserIdleSystemSleep, with the seconds left before it lets go:

pmset -g power settings and pmset -g assertions listing a caffeinate PreventUserIdleSystemSleep assertion on macOS 27

On your own Mac, look for a non-zero PreventUserIdleSystemSleep or PreventUserIdleDisplaySleep count, then read the owners underneath: a browser tab playing media, a backup client or a forgotten caffeinate are the usual ones. That makes caffeinate the clean way to keep a Mac awake for one job, such as caffeinate -i rsync -a ~/Projects/ /Volumes/Backup/Projects/, because the assertion lasts exactly as long as the command. A headless Mac mini that runs builds or a local model needs the opposite, a permanent sleep 0; the buying side of that setup is in the guide to the best Mac mini for AI agents.

Scheduled wakes are separate from both, and you set them once. sudo pmset repeat wakeorpoweron MTWRF 08:00:00 showed up in pmset -g sched as wakepoweron at 8:00AM weekdays only. It stays in the power settings until you remove it, and sudo pmset repeat cancel did that, leaving pmset -g sched empty.

defaults write changes preferences, not behaviour

A defaults write stores a key in a preference domain and nothing more. Whether anything changes depends on the app reading that key, and Finder and the Dock read theirs at launch, so a successful write with no visible effect usually means the app is still running with the old value. That is why most Finder and Dock tweaks end in a killall. The sequence below writes two keys, checks their types and removes one.

defaults write com.apple.finder AppleShowAllFiles -bool true
defaults read-type com.apple.finder AppleShowAllFiles
defaults write com.apple.dock autohide-delay -int 1
defaults read-type com.apple.dock autohide-delay
defaults delete com.apple.dock autohide-delay
killall Dock

Three things in the result are worth reading closely. Before the first write, defaults read com.apple.finder AppleShowAllFiles failed with Domain 'com.apple.finder' not found, which only means nothing has been saved yet, not that the key is wrong. The -int 1 write changes the type with no warning: an earlier run had stored the same key with -float 0, and after the integer write read-type says Type is integer. And killall Dock answered No matching processes belonging to you were found, because an SSH session has no Dock to restart:

defaults write mac example: defaults write, defaults read-type and defaults delete for Finder and Dock keys on macOS 27

A silent type change is the trap. defaults writes whatever type you pass, and an app that expects a boolean or a float may ignore a key of another type, so check an existing key with read-type before you overwrite it. These tweaks wrote and read back cleanly on macOS 27, each with the process it needs restarted:

  • com.apple.finder AppleShowAllFiles: Finder
  • com.apple.finder ShowPathbar: Finder
  • com.apple.dock autohide-delay: Dock
  • com.apple.desktopservices DSDontWriteNetworkStores: log out and back in

Before you make a batch of changes, keep a copy with defaults export com.apple.dock dock-backup.plist, then plutil -p dock-backup.plist shows what you saved. Undo a single key with defaults delete, which puts the app back on its built-in default; reading the key afterwards returns Could not find key 'autohide-delay' in domain 'com.apple.dock', the proof it’s gone. Avoid editing the .plist files under ~/Library/Preferences directly, because the cfprefsd daemon caches preferences in memory and can write its copy back over your edit.

launchctl load is the legacy path

launchd is the Mac’s systemd, and launchctl is its systemctl. Most tutorials still tell you to run launchctl load, but the man page on macOS 27 files load and unload under LEGACY SUBCOMMANDS and names bootstrap, bootout, enable and disable as the replacements. The reason to switch showed up in testing: a launchctl load that failed printed Load failed: 5: Input/output error and still exited 0, so a setup script would have carried on as if the job were running. bootstrap returned exit code 5 for the same failure.

The new commands take a domain target, and the folder holding the plist decides which domain the job belongs in:

  • ~/Library/LaunchAgents: gui/$(id -u), while you’re logged in
  • /Library/LaunchAgents: every user’s desktop session
  • /Library/LaunchDaemons: system, as root from boot
  • /System/Library/LaunchDaemons: Apple’s own, protected by SIP

What happens when you bootstrap an agent into gui/ over SSH? It fails with Bootstrap failed: 125: Domain does not support specified action, because the gui domain only exists for a user logged in at the desktop. The user/$(id -u) domain did not help either. From SSH it returned 5: Input/output error, even with sudo. On a headless Mac you manage over SSH, a job that must run without anyone logged in belongs in /Library/LaunchDaemons anyway, so that’s the path tested end to end here. Create the plist:

sudo vim /Library/LaunchDaemons/com.example.backup.plist

This job appends a timestamp to a log every 300 seconds, which is enough to prove it runs. Swap the shell command for your real backup script:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.example.backup</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/sh</string>
    <string>-c</string>
    <string>date >> /tmp/com.example.backup.log</string>
  </array>
  <key>StartInterval</key>
  <integer>300</integer>
</dict>
</plist>

The launchctl man page requires daemon plists to be owned by root and closed to group and world writes, so set the ownership and mode, then lint the file before loading it. A broken plist gets a precise answer from plutil (Value missing for key inside <dict> at line 15 for a dangling key), while launchd only says the load failed:

sudo chown root:wheel /Library/LaunchDaemons/com.example.backup.plist
sudo chmod 644 /Library/LaunchDaemons/com.example.backup.plist
plutil -lint /Library/LaunchDaemons/com.example.backup.plist
sudo launchctl bootstrap system /Library/LaunchDaemons/com.example.backup.plist
sudo launchctl kickstart -k system/com.example.backup

A StartInterval job does not run the moment it loads, which is why the kickstart is there: it forces one run so you can check the result without waiting five minutes. The capture shows the whole cycle, from the gui error to runs = 1, last exit code = 0 and a timestamp in the log:

launchctl bootstrap error 125 over SSH, then launchctl bootstrap, kickstart, list and print for a LaunchDaemon on macOS 27

In launchctl list, the three columns are the PID, the last exit status and the label. A dash in the PID column is normal for a job between runs, a non-zero status means its last run failed, and a negative one means a signal killed it. The full print output (path, arguments, environment, run count) is for people, not parsers: the man page says it “does not constitute an API”. Three errors you’ll meet while iterating:

  • Bootstrap failed: 5: Input/output error: often already loaded, so check with print
  • Boot-out failed: 3: No such process: nothing by that label is loaded
  • Could not find service ... in domain: wrong domain or label

After editing the plist, run bootout and bootstrap again, since kickstart -k only restarts the job with the definition launchd already holds. disable and enable only flip a persistent override; sudo launchctl print-disabled system listed "com.example.backup" => disabled after one and enabled after the other, and neither unloaded the job, since the bootout afterwards still found it. When you’re done with it, remove the job with sudo launchctl bootout system/com.example.backup, then delete the plist. Apple’s own walkthrough is the script management with launchd page in the Terminal User Guide.

mdfind asks the index, find walks the disk

find works on a Mac exactly as on Linux, and on a large home folder it’s just as slow. mdfind queries the Spotlight index instead, so it answers almost at once and searches file contents as well as names. On a nearly empty home folder the gap was already 0.011 seconds for mdfind -name invoice against 0.129 for the equivalent find ~, and it grows with every file you own.

For the test, two small runbook files and a PDF went into ~/Documents/runbooks. You can then search for a phrase inside them and for PDFs by type.

mdfind -onlyin ~/Documents "kubernetes upgrade" 2>/dev/null
mdfind -onlyin ~/Documents 'kMDItemContentType == "com.adobe.pdf"'
mdls -name kMDItemContentType -name kMDItemKind -name kMDItemFSSize ~/Documents/runbooks/k8s-upgrade-notes.pdf

The phrase search found both the text file and the PDF, and the type query found only the PDF. mdls shows why you should query on kMDItemContentType (a UTI such as com.adobe.pdf) rather than kMDItemKind: the kind is the localized string PDF document, which changes with the system language:

mdfind content and metadata queries with mdls showing kMDItemContentType for a PDF on macOS 27

Three behaviours from the run change how you script against mdfind:

  • New files take seconds to appear: a search 10 seconds after writing them came back empty, and mdls printed (null)
  • mdfind -name prints two [UserQueryParser] Loading keywords lines to stderr on macOS 27, so add 2>/dev/null
  • Results include system paths: -name invoice also matched INVoiceShortcut.h in the Command Line Tools SDK

Scope with -onlyin when you want results from one tree, and fall back to find for volumes where mdutil -s reports indexing disabled. Metadata queries combine with &&, so mdfind 'kMDItemContentType == "com.adobe.pdf" && kMDItemFSSize > 50000000' returns every PDF over 50 MB the index knows about. On the test Mac that list was empty, which is the right answer for a fresh machine.

Desktop tools fail over SSH

A handful of the commands people love most about the Mac terminal talk to the logged-in desktop, not to the system. Run them from an SSH session to a headless Mac and they fail, some with a clear error and some silently, which is easy to misread as a broken install. Over SSH on the test Mac:

  • pbcopy exited 1 with no message
  • open . failed with Launchd could not find job
  • screencapture -x printed could not create image from display
  • killall Dock and killall Finder found no process

You are seeing the same cause in all of them as in the launchctl 125 error, which is no gui session for your user. In Terminal on the Mac itself, each works as the table describes. Over SSH, you copy files with scp instead of the clipboard, and use a LaunchDaemon rather than an agent for anything that has to run without a login. The same session also shows the BSD sed difference covered next:

BSD sed -i error, sed -i with an empty suffix, and pbcopy and open failing in an SSH session on macOS 27

At the end of that capture sits meminfo, Apple’s memory breakdown, which reports pages and megabytes per category. It’s the closest thing to free -h on a Mac, and it does the page maths for you. vm_stat only prints page counts, and sysctl -n hw.pagesize returned 16384 on the M4, so multiplying those counts by 4096 out of Linux habit gives you a quarter of the real figure.

Linux habits that change on a Mac

Most of the confusion on a Mac terminal comes from muscle memory. macOS ships BSD versions of the core utilities and its own tools for the hardware, so the Linux command you type either does not exist or takes different flags. The left column is what you would type on a Linux box, and every Mac command in the middle column ran on the test machine.

On LinuxOn a MacWhat changes
lsblk, fdisk -ldiskutil listDisk identifiers, synthesized APFS containers
lscpu, free -hsysctl, meminfovm_stat counts 16 KB pages
ip a, nmcliipconfig getifaddr, networksetupService names instead of interfaces
systemctllaunchctlDomains: gui/UID and system
journalctl -u sshdlog show --predicate 'process == "sshd"' --last 1hUnified log, predicate filters
hostnamectlscutil --get ComputerNameThree names: ComputerName, LocalHostName, HostName
locatemdfindUses the Spotlight index
xclip, xdg-openpbcopy, openBuilt in, desktop session only
sed -i 's/a/b/' fsed -i '' 's/a/b/' fBSD sed needs a backup suffix, even an empty one

The sed -i row catches more scripts than any other line here. GNU-style sed -i "s/x/y/" notes.txt on a Mac takes the expression as the backup suffix and then parses the file name as a command, which is why the error reads extra characters at the end of n command: the n is the first letter of notes.txt. Pass an empty suffix and it works. If you’d rather keep GNU behaviour, Homebrew’s gnu-sed installs it as gsed, and keeping Homebrew auto-update under control stops that quick install from turning into a long update.

The hostname row is the other surprise. scutil keeps three separate names, and on the test Mac ComputerName was Mac mini, LocalHostName was Mac-mini (the Bonjour .local name) and HostName was not set at all, so the shell prompt falls back to the local name. Set the one your tooling reads, and check the other two before you blame DNS. Git, SSH keys and compilers come with the Xcode Command Line Tools, which softwareupdate -l listed as version 27.2 alongside the macOS 27.2 update on this machine.

Keep reading

Claude Code Cheat Sheet: Commands, Shortcuts and Flags (PDF) AI Claude Code Cheat Sheet: Commands, Shortcuts and Flags (PDF) OpenAI Codex CLI Cheat Sheet: Shortcuts, Commands, Flags (PDF) AI OpenAI Codex CLI Cheat Sheet: Shortcuts, Commands, Flags (PDF) Linux and DevOps Cheat Sheets (Free PDF Pack) Cheat Sheets Linux and DevOps Cheat Sheets (Free PDF Pack) Mac Developer Setup: Python (uv), Node, Java and PostgreSQL macos Mac Developer Setup: Python (uv), Node, Java and PostgreSQL Homebrew Cheat Sheet: brew Commands, Casks, Services (PDF) macos Homebrew Cheat Sheet: brew Commands, Casks, Services (PDF) Curl Cheat Sheet: Headers, Auth, Uploads, Retries, Proxies, TLS Cheat Sheets Curl Cheat Sheet: Headers, Auth, Uploads, Retries, Proxies, TLS

Leave a Comment

Press ESC to close