Skip to content

Instantly share code, notes, and snippets.

@sergiitk
Last active August 7, 2024 15:43
Show Gist options
  • Save sergiitk/a87207a8af11d6e6d807 to your computer and use it in GitHub Desktop.
Save sergiitk/a87207a8af11d6e6d807 to your computer and use it in GitHub Desktop.
OSX terminal tips an tricks

OS X terminal tips an tricks

Shell tools

System

  • sw_vers — Print Mac OS X operating system version information
  • system_profiler — Reports system hardware and software configuration.
  • system_profiler SPHardwareDataType — Hardware overview.
  • hostinfo — Host information.
  • nvram -p — Print all of the firmware variables.
  • getconf DARWIN_USER_CACHE_DIR — Retrieve standard configuration variables
  • /usr/libexec/path_helper — Helper for constructing PATH environment variable
  • open -a "Google Chrome" --args --profile-directory=Default — Open app with args
  • atsutil fontprotection -fonts — List protected system fonts
  • plutil -convert xml1 binary-property-list-to-convert.plist, plutil -convert binary1 XML-property-list-to-convert.plist

Services

  • _ launchctl stop org.macports.nginx — Restart nginx`
  • _ launchctl list | grep -i ssh — Search lanuchd services
  • _ launchctl list | grekp -P '^[0-9]+' — Show running services
  • _ launchctl list org.macports.nginx — Show nginx service info

Filesystem and disks

  • man 7 hier - BSD filesystems standard layout
  • diskutil list — Lists and disks and theirs partitions.
  • _ gdu --si --summarize /^(dev|Volumes)(/^@^F) | gsort -h -r — Root directory stats: no symlinks, no empty dirs, no /Volumes and /dev

System limits

  • Prints all the resource limits — launchctl limit
  • Prints kernel variables (here: file limits) — sysctl -a | grep files

Visibility

  • l | grep -P '^[-rwx]+@' — List hidden files and folders
  • chflags hidden Maildir — Hide folder
  • chflags nohidden Maildir — Unmask folder
  • defaults write com.apple.Finder AppleShowAllFiles -bool yes — Display hidden files in Finder
  • defaults write com.apple.Finder AppleShowAllFiles -bool no — Don't display hidden files in Finder

Networking

  • /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport — get information for 802.11 interface
  • syudo scutil --nwi show active network interfaces
  • less /var/log/wifi.log — WiFi log
  • dscacheutil -q service -a port 22 — Resolve service name at port 22
  • dscacheutil -q service -a name ssh — Resolve port for ssh service
  • dscacheutil -q protocol | less — List available protocols
  • dscacheutil -q host — Show parsed hosts file
  • dscl . -list /SharePoints — List all available network shares
  • dscl . -read /SharePoints/img — Display share info
  • dscl . -readall /SharePoints — Display info for all shares

Print and scan

Miscellaneous

  • otool -L /usr/libexec/FDERecoveryAgent — OSX's version of ldd
  • CLICOLOR_FORCE=1 ls -l /bin | grep k — CLICOLOR_FORCE passes colors through pipes
  • lsappinfo — Show apps meta-information

User and domain management

Directory Service

  • dscacheutil -q user -a name sergii — Display sergii's login info
  • dscl . -search /Users name [email protected] — Search for local users by assigned email (name alias), full match
  • dscl . -list /Users | grep vygnan — Search for local users by name, grep
  • dscl . -search /Users name sergii — Display sergii's Directory Service info
  • dscl . -read /Users/sergii — Display sergii's full data
  • dscl -plist . -read /Users/sergii — Display sergii's full data in plist format
  • dscl . -list /Users UserShell — List all users with theirs shells in columns (UserShell — field from read)
  • dscl . -readall /Users UserShell UniqueID — Display all users and selected properties (nl separated)
  • dscl . -list /Groups — List all groups
  • dscl -f /var/db/dslocal/nodes/Default localonly -list /Local/Default/Users — read data from Directory Service specified folder
  • _ ls -laF /var/db/dslocal/nodes/Default/ — Local Directory Service database
  • open -a "Directory Utility" — Directory Utility GUI
  • man 8 opendirectoryd — Show Open Directory manual
  • odutil show sessions — Show active sessions
  • odutil show nodenames — List all available node names
  • odutil show configuration /Search — Show /Search node configuration
  • dseditgroup -o read staff — Manipulate group records with the Open Directory API (dscl alternative)

Other services

  • mkpassdb -list — Outputs all of the SASL mechanisms available to the Mac OS X Server Password Server.

Reports, statistics and debugging

  • _ systemstats --dashboard
  • man pmset
  • iostat -w1 — Report I/O statistics every second.
  • kextstat — Display status of loaded kernel extensions.
  • diskutil info /Volumes/Macintosh — Mounted volume info
  • _ opensnoop -veg -n php-cgi — snoop php opens
  • _ rwsnoop -Pn Sublime — snoop read/writes of Sublime Text
  • _ iosnoop -vei — Snoop IO, (-A = full)
  • _ execsnoop -v — Snoop new process execution
  • _ fs_usage -w | grep Safari
  • _ sc_usage Finder -e -s2
  • _ diskhits /var/log/system.log — disk access for the cache misses only.

Virtual memory

  • Documentation — man dynamic_pager, About the Virtual Memory System
  • Startup item — defaults read /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
  • Disable swap — _ launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
  • Display swap usage — sysctl vm.swapusage
  • Monitor virtual memory stats — vm_stat 1
  • Force disk cache to be purged — purge
  • Display the virtual memory regions allocated in a process — vmmap

Debug tools

  • leaks — Searches for leaked memory — memory that the application has allocated, but has been lost and cannot be freed.
    • sudo leaks -nocontext -nostacks 110
  • heap — List all the malloc-allocated buffers in the process's heap
  • stringdups — Identify duplicate strings or other objects in malloc blocks of a target process
  • iprofiler

Soft

Spotlight

  • mdutil -i off /Volumes/volume — Turn off indexes at mountPoint
  • mdfind — Finds files matching a given query
  • mdls .gitignore — Lists the metadata attributes

Keychain

  • security — Command line interface to keychains and Security framework
    • security dump-keychain -ag login.keychain — Dump login decrypted items and full ACL
    • security find-internet-password -g -a stk — Show decrypted password for stk account
    • security find-generic-password -g -a AirPort -l thenetwork5GHz — Display WiFi password
  • /usr/bin/ssh-add -K — Save password for ssh keys to the keychain

Resources

  • open /Library/Documentation — Browse bundled tutorials
  • ls /usr/libexec — System daemons & system utilities
  • p /System/Library/CoreServices/*.app(/:t) — List core services apps
  • p /System/Library/Services/*(/) — Other services
  • quick-look /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/*.icns — Preview all icons available
  • quick-look /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/*Folder*.icns — Preview folder icons available
  • cat /etc/periodic/daily/110.clean-tmps — Periodic job to cleanup tmp files, see man periodic

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment