The best laptop money can buy:
https://www.apple.com/uk/macbook-pro/
If you don't have an M3 Pro / Max - you're missing out on an excellent (but overpriced) machine.
This is where you should be spending your life if you're a techie, with a browser to supplement referencing documentation.
$COLUMNS
- 179 column width on my MacBook Pro 13" terminal
- 204 on my MacBook Pro Retina 15" terminal
- 215 on my Macbook Pro M3 2023 terminal - resolution gets better over time
The best most widely used package manager for Mac.
See brew.md for how to use it and great package lists I've spent years discovering and building up.
A list of commands is provided at https://ss64.com/mac/.
Cmd
-Space
- opens Spotlight search to auto-complete and open anything quickly.
Open a file / folder / URL / Application. Use -a
to select which app to use to open it.
Use -e
to edit the file in TextEdit.
Open URL in the default web browser:
open https://google.com
Open current directory in Finder:
open .
Open image in the default app, usually Preview:
open file.jpg
You can also drag to the Terminal to paste a file or directory's path, or right-click copy and paste into the terminal to get its path on your command line.
Copy from stdin to clipboard:
pbcopy < input.txt
Paste from clipboard to stdout:
pbpaste > output.txt
Cmd
+ Shift
+ 3
Switches to a cross-hair to drag to what you want to screenshot.
Cmd
+ Shift
+ 4
You may be prompted to allow Terminal to record the screen under Privacy & Security
-> Screen Recording
the first
time - it'll tell you that you have to restart the Terminal, but it worked for me without a restart.
Switches to select window to capture:
screencapture -W /tmp/screenshot.png
Interactive mode with full toolbar, same as the Screenshot.app
:
screencapture -i -U /tmp/screenshot.png
Video recording mode for 10 seconds (without -V
it will record until you Ctrl
-c
it):
screencapture -v -V 10 /tmp/videocapture.mp4
So many great options from delayed screenshots, copy to clipboard, open in Preview, capture a coordinate rectangle (great for automation!), see:
screencapture --help
in the Utilities folder is easy to use:
open /System/Applications/Utilities/Screenshot.app
dscacheutil -flushcache
sudo killall -HUP mDNSResponder
Stats gives many nice toolbar stats on your Mac's performance for CPU, GPU, RAM, Disk, Network and Battery.
Battery even tells you:
- time to discharge
- time to charge
- number of cycles (although this one I'm sure is only since installation of Stats)
- battery health
- which apps which are consuming a lot of energy for you to kill them if you're not needing them, helping your battery life when on the move
If like me, you hate the time lost in graphics sliding effect from one desktop workspace to another, especially caused
by apps like Windows Virtual Desktop in Remote Desktop opening to full screen, and just prefer good old fashioned
Cmd
-Tab
, then you can remove the extra workspaces as
described here
by pressing F3 and then hovering on and clicking the X to delete the extra workspaces.
Make your Mac speak. I use this to impress the kids, or even send a message from my study to my living room computer
by running say
over an SSH login to the computer downstairs for them to hear!
say "Daddy is the greatest"
You can also pipe in text:
echo "Daddy is the greatest" | say
Try different voices, list them like this
say -v ?
Speak from a text file and save it to an audio file:
say -f words.txt -o myaudioclip.aiff
The equivalent of locate
on Linux, uses the Spotlight index:
mdfind [-onlyin /path/to/directory] [-name "$filename"] "$term"
Erase and rebuild the Spotlight index:
mdutil -E
Enable / disable Spotlight indexing for a given volume or entirely:
mdutil -i
This accesses launchd
, Mac's init script equivalent.
See which launchd
scripts are loaded:
launchctl list
Stop and unload script, add -w
to remove it from the boot sequence:
sudo launchctl unload [path/to/script]
Launch scripts are found in the following locations:
~/Library/LaunchAgents
/Library/LaunchAgents
/Library/LaunchDaemons
/System/Library/LaunchAgents
/System/Library/LaunchDaemons
Blog post on cool things launchd can do, like watching and executing on files that are dropped into directories.
Using graphical Disk Utility is easiest:
open /System/Applications/Utilities/Disk\ Utility.app
Great tutorial:
Part 1 - List, Verify, Repair, Rename, Erase volumes
Part 2 - Partition, Format, Split / Merge Partitions
Part 3 - Create .dmg
disk images from a Volume / Folder, Encrypted Disk Image, Resize Image, Restore Image
diskutil list
diskutil mount
and diskutil mountDisk
are the same
diskutil mount /dev/disk4s2
diskutil unmount /dev/disk4s2
or by volume location:
diskutil unmount "/Volumes/$NAME"
Mount a partition read-only if having trouble and trying to recover data:
diskutil mount readOnly /dev/disk4s2
Mount at a different location to the default /Volumes/<partition_metadata_name>
:
diskutil mount /dev/disk4s2 -mountPoint /path/to/dir
Mount / unmount partitions on a whole disk by reading its partition table:
diskutil mountDisk disk10
diskutil unmountDisk disk10
Verify a volume:
diskutil verifyVolume "/Volumes/$NAME"
Repair volume:
diskutil repairVolume "/Volumes/$NAME"
diskutil verifyPermissions "/Volumes/$NAME"
diskutil repairPermissions "/Volumes/$NAME"
Format a partition This is risky because there is no confirmation, better to do this from Disk Utility:
diskutil eraseDisk "$filesystem" "$name" "/dev/$diskN"
See which filesystems are available for formatting:
diskutil listFilesystems
Rename a disk:
diskutil rename "$volume_name" "$new_volume_name"
APFS requires GPT partition table
disk="disk4"
partition_table="GPT"
name="MyVolume"
filesystem="APFSX" # AppleFS case-sensitive, found from 'diskutil listFilesystems' above
size="0b" # integer + units suffix (b, m or g for bytes, megabytes or gigabytes) - '0b' uses all space
diskutil partitionDisk "/dev/$disk" "$partition_table" "$filesystem" "$name" "$size"
diskutil partitionDisk /dev/"$disk" "$partition_table" "$filesystem" "First" "$size" \
"$filesystem" "Second" "$size" \
"$filesystem" "Third" "$size" \
"$filesystem" "Fourth" "$size" \
"$filesystem" "Fifth" 0b # '0b' to use up all remaining space
Partition splitting doesn't seem to work with APFS, only macOS Extended, as APFS tells you to
diskutil apfs deleteContainer disk10
instead which leaves you with free space to create a new partition.
Either use Disk Utility above, a command like diskutil eraseDisk ...
or the more portable unix command dd
with a
custom command like this to do a moderate 3 pass overwrite
(tune number of passes
variable to suit your level of data recovery paranoia, eg. DoD standard 7 passes):
WARNING: disk numbers may shunt up in numbers as you insert more removal drives, especially for 'synthesized' virtual disks that display for volume containers
passes=3
time \
for number in $(seq $passes); do
echo pass $number
echo
time sudo dd if=/dev/urandom of=/dev/disk4 bs=1M
echo
done
Note: multiple passes are only for old inaccurate HDDs rotating mechanical metal platter disk. For SSDs, you only need a single pass.
Load and start a service from a plist
file:
sudo launchctl load -F "/System/Library/LaunchDaemons/$name.plist"
sudo launchctl start "com.apple.$name"
Stop and unload a service:
sudo launchctl stop "com.apple.$name"
sudo launchctl unload "/System/Library/LaunchDaemons/$name.plist"
See dhcp.md for a practical example of using this for the built-in tftp server for PXE boot installing Debian off your Mac.
Macs and many computers don't come with CD/DVD anymore to save space, so you can either buy an external USB dvd-writer or create bootable USBs.
To create a bootable USBs from ISO image files intended for CD/DVDs in order to use them to install Linux or use a disk wiping distro like DBAN or ShredOS, you can download Etcher or use mac_iso_to_usb.sh from DevOps-Bash-tools:
mac_iso_to_usb.sh "$iso" # /dev/disk4
- UNetbootin app from github
- DiskUtility
- CLI
Set your filename in a variable so the following commands can be executed as is without editing:
export ISO="memtest86+-5.01.iso"
Convert it to make it bootable - will automatically add .dmg
suffix => .img.dmg
:
hdiutil convert -format UDRW -o "$ISO.img" "$ISO"
Figure out which is the USB disk - be careful or you'll destroy your system!
diskutil list
diskutil unmountDisk /dev/diskN
Tip: prefixing disk with 'r' uses raw disk which is faster:
sudo dd if="$ISO.img" of=/dev/rdiskN bs=1m # or 1M
diskutil eject /dev/diskN
Burn CD - insert blank CD then:
hdiutil burn "$ISO"