Mac for Geeks

## references

- dynamic man

- CLI guides 10.3 (10.3) 10.6 10.9

Mac for Unix Geeks 4E (Leopard) [2008]

- Developer Tools (XCode) - gcc, make - Command Line Developer Tools for OS X - autoinstall on first run

## history AT&T UNIX -> A/UX (1991 Quadra 700/900) NeXTStep: (1989) 4.3BSD + microkernel + Objective- (1991) Tim Berners-Lee uses NeXTCube to create Web 1996 MkLinux for PowerPC 1997 Apple acquires NeXT OPENSTEP -> Darwin on XNU (modified Mach) kernel + I/O Kit 2001 Mac OS X 10.0

## access Terminal Command-S at startup >console at login box (if showing user/password)

## drag folder to Terminal window to insert path option-click to reposition cursor within shell command save shell scripts with .command suffix to make them clickable apps

## integration - where Unix appears Console == tail -f logs

firewall via ipfw / pf sharing via File Sharing (smbd), Remote Login (sshd), Internet Sharing (natd), Web (Apache), (VNC) printing via CUPS - $ cupsctl WebInterface=yes

OS X Server - CardDAV, CalDAV, DHCP (bootpd), Wiki/WebDAV, Mail (cyrus/dovecot/postfix), VPN (raccoon/ pppd), DNS (bind)

X11 / XQuartz

## paths FreeBSD file structure title-case (Apple-land) vs lowercase (Unix-land) /private (etc, tmp, var) /Applications, Developer, Library, Network, System, Users, Volumes

/.DocumentRevisions-V100/ (Versions) /.-V100/ (metadata) /.Trashes/, ~/.Trashes/

## commands

* open open [path/to/document] || [path/to/folder] || [app name] # open document in alt editor $ open -a textwrangler test.txt # open URL in default browser open [URL] opendiff file1 file2 - launches FileMerge (part of Developer Tools)

* clipboard pbcopy < filename $ command | pbcopy pbpaste pbpaste > filename $ pbpaste | command

* qlmanage -p [path/to/file] - file

* text nano vi -> vim emacs

* files applesingle / binhex / macbinary dot_clean .DS_Store ( settings, e.g. icon location and window size) ls -le (ACL) ls -l@ (extended attributes)

[Spotlight] mdfind (search) / mdls (view metadata) / mdutil (manage metadata) / mdimport scp -E The ʻ-Eʼ flag preserves extended attributes, resource forks, and ACL information. textutil $ textutil -info MyFile $ textutil -convert html MyWordFile -output /tmp/webfile.html

* PLists == Property Lists, defaults # set user LoginHook sudo defaults write com.apple.loginwindow LoginHook /path/to/script

Property LIst Editor (XCode)

/usr/libexec/PlistBuddy # Allow user to set DVD region once upon first insertion of disc $ /usr/libexec/PlistBuddy -c "Set :rights:system.device.dvd.setregion.initial:class allow" /etc/authorization plutil

## remote admin * disks asr - Apple System Restore rsync | ditto | dd bless - manage boot / startup volumes createhomedir diskutil ( - physical disks) hdiutil (DU - disk images) drutil (DU - disk burners) disktool (deprecated)

* network airport $ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s networksetup # check DNS servers on Ethernet interface $ networksetup -getdnsservers ethernet scutil - system config $ scutil -r IP $ scutil --get ComputerName (sharing) | LocalHostName () | HostName $ scutil --dns

* software / pkgutil / packagemaker softwareupdate

* system info sysctl - kernel state $ sysctl -n hw.model $ sysctl -n machdep.cpu.brand_string $ sysctl vm.loadavg system_profiler

* system settings nvram -p pmset #Set System Sleep Preferences | 0 = Off | 15 = 15 Min | 20 = 20 Min | etc | $ pmset sleep 0 systemsetup # List startup disks $ systemsetup -liststartupdisks # Show current startup disk $ systemsetup -getstartupdisk # Change startup disk $ systemsetup -setstartupdisk path # Set time zone and time server. $ systemsetup -setusingnetworktime on $ systemsetup -settimezone America/New_York -setnetworktimeserver time.apple.com

# Activate WakeOnLAN. $ systemsetup -setwakeonnetworkaccess on # Set computer to start up after power failure $ systemsetup -setwaitforstartupafterpowerfailure seconds (0 | 30 / +30 )

* user/group dscl dsmemberutil - to see what group a user or another group are a member of, or check user/group UUIDs dseditgroup - To edit, create, manipulate, or delete groups # Allow all local users to add/remove printers, as part of the lpadmin group, substitute localadmin for your admin's short username dseditgroup -o edit -u localadmin –t group -a staff _lpadmin dscacheutil - To work with various Directory Service caches, including LDAP and DNS # flush DNS cache 10.4: $lookupd -flushcache 10.5/10.6: dscacheutil -flushcache 10.7/10.8: sudo killall -HUP mDNSResponder dsenableroot - to enable root

- - - ## misc automator / amlint / osascript caffeinate (10.8+) - disable sleep osascript scriptfile - run $ osascript -e 'Applescript syntax' screencapture $ screencapture -m screenfile.png

## launchctl /System/Library/LaunchDaemons - Apple system daemons /System/Library/LaunchAgents - Apple agents (all users) /Library/LaunchDaemons - third party system daemons /Library/LaunchAgents - third party agents (all users) ~/Library/LaunchAgents - third party agents (logged-in user) Schedule via StartCalendarInterval / StartInterval keys

## extending - MacOSForge.org - open sourced Apple projects (WebKit, XQuartz) - MacPorts.org | FinkProject.org | Homebrew (Brew.sh)

## tools - edit Hosts - Icefloor - edit PF Platypus Term2 Visor