n8felton
9/23/2016 - 1:30 PM

macOS Command Snippets

macOS Command Snippets

# Retrieve the Serial Number
ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}'

# Retrieve the Hardware UUID
ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformUUID/{print $(NF-1)}'

# Retrieve the Model Identifier, e.g. iMac16,1; Macmini7,1' VMware7,1
sysctl -n hw.model

# Convert macOS SMB path to UNC path
echo "smb://myserver.example.com/sharename" | sed  -e 's_smb://\(.*\)_\\\\\1_g' -e 's_\/_\\_g'
# \\myserver.example.com\sharename

# Convert UNC path to macOS SMB path
echo "\\myserver.example.com\sharename" | sed  -e 's_\(.*\)_smb:\\\1_g' -e 's_\\_\/_g'
# smb://myserver.example.com/sharename

# Retrieve the Darwin Cache or Temp dir variables
getconf DARWIN_USER_CACHE_DIR
getconf DARWIN_USER_TEMP_DIR
# Root Defaults
# Cache: /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/C/
# Temp:  /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/
# User Example
# Cache: /var/folders/wt/c230x4391yn3qmb9j2sb90v40000gn/C/
# Temp:  /var/folders/wt/c230x4391yn3qmb9j2sb90v40000gn/T/

# Determine the home directory for all users on a machine
USERS=$(dscl /Local/Default -list /Users uid | awk '($2>=500) && ($2<=10000) {print $1}')

for USERNAME in $USERS; do
  USER_HOME=$(eval echo "~$USERNAME")
  echo $USER_HOME
done