Helpfull command line tools for macOS
System tools
Get system version
sw_vers - print macOS system version information
sw_vers
sw_vers --productVersion
sw_vers --buildVersion
List all installed system updates
softwareupdate - system software update tool
softwareupdate –-history
softwareupdate --list
softwareupdate --list-full-installers
softwareupdate --install --agree-to-license
softwareupdate --install-rosetta
Hardware information
system_profiler - reports system hardware and software configuration
system_profiler -listDataTypes
system_profiler SPHardwareDataType
Check uptime
uptime - show how long system has been running
uptime
Check dick usage
df - display free disk space
df -h
User and Group Information
Query user and group data
dscl - Directory Service command line utility
dscl . -list /Users # list all local users
dscl . -list /Groups # list all local groups
dscl . -read /Users/jschlaht # show all attributes of a user
dscl . -read /Users/jschlaht RealName # show full name of a user
dscl . -read /Users/jschlaht UniqueID # show user ID (UID)
dscl . -read /Users/jschlaht PrimaryGroupID # show primary group ID
dscl . -list /Users UniqueID # list all users with their UIDs
dscl . -list /Groups GroupMembership # list all groups with their members
Check which groups a user belongs to
id jschlaht
groups jschlaht
Read admin group members
dscl . -read /Groups/admin # show all attributes of the admin group
dscl . -read /Groups/admin GroupMembership # list all members of the admin group
dscl . -read /Groups/admin GroupMembers # list member GUIDs of the admin group
Search for a user by full name
dscl . -search /Users RealName "Jurij Schlaht"
Network Troubleshooting
Get current IP and interface details
ifconfig - configure network interface parameters
ifconfig
ipconfig - view and control IP configuration state
ipconfig getsummary en0
Test DNS resolution
ping - send ICMP ECHO_REQUEST packets to network hosts
ping www.heise.de
dig - DNS lookup utility
dig heise.de
nslookup - query Internet name servers interactively
nslookup 192.168.178.1
Check default gateway
netstat - show network status
netstat -nr | grep default
Test port connectivity
nc - arbitrary TCP and UDP connections and listens
nc -vz jschlaht.jamfcloud.com 8443
Cronjobs and background processes
Launch Agents and Daemons
List all LaunchAgents
ls /Library/LaunchAgents
List all LaunchDaemons
ls /Library/LaunchDaemons
Check status of a specific LaunchDaemon
sudo launchctl list | grep "com.jamf"
Load a LaunchDaemon manually
sudo launchctl load /Library/LaunchDaemons/com.company.script.plist
Unload a LaunchDaemon manually
sudo launchctl unload /Library/LaunchDaemons/com.company.script.plist
MDM Profiles
Handle MDM profiles
Check MDM profile status
profiles - Profiles Tool for macOS
sudo profiles -P
List all installed profiles
profiles -C
Logs
View log messages
log - Access system wide log messages created by os_log, os_trace and other logging systems.
View MDM framework logs
log show --predicate 'eventMessage contains "mdm"' --info --last 1h
Check logs for profile installation
log show --predicate 'eventMessage contains "Profile installation failed"' --last 1h
Apps
Get apps information
Check specific app version
defaults read /Applications/Safari.app/Contents/Info CFBundleShortVersionString
File Permissions
Change file permissions
chmod - change file modes or Access Control Lists
The syntax is chmod [who][operator][permission] file, where:
- who:
u(user/owner),g(group),o(others),a(all) - operator:
+(add),-(remove),=(set exactly) - permission:
r(read),w(write),x(execute)
chmod u+x script.sh # make executable for owner
chmod g+x script.sh # make executable for group
chmod o-r file.txt # remove read permission for others
chmod 755 script.sh # rwxr-xr-x (owner: rwx, group: rx, others: rx)
Make files in a directory executable for the group
chmod -R g+x /path/to/directory
Input/Output Redirection
Save output to a file
Use > to write stdout to a file (overwrites) or >> to append.
ls -la > output.txt # write output to file (overwrite)
ls -la >> output.txt # append output to file
sw_vers > system-info.txt # save system version info to file
Save only error output to a file
Use 2> to redirect stderr to a file. To suppress errors entirely, redirect to /dev/null.
find / -name "*.log" 2> errors.txt # save only errors to file
find / -name "*.log" 2>> errors.txt # append errors to file
find / -name "*.log" 2> /dev/null # suppress all errors
find / -name "*.log" > out.txt 2> err.txt # save stdout and stderr separately
Pass parameters from a file to a command
xargs - construct argument list and execute utility
cat files.txt | xargs rm # delete all files listed in files.txt
cat hosts.txt | xargs -I {} ping -c 1 {} # ping each host listed in hosts.txt
xargs chmod +x < scripts.txt # make all files listed in scripts.txt executable
Chaining Commands
Run multiple independent commands in one line
Use ; to run commands sequentially regardless of whether the previous command succeeded.
cd ~/Downloads; ls; du -sh . # change dir, list files, show size — all run no matter what
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Pipe commands — pass output to next command
Use | to pass the stdout of one command as stdin to the next. Commands are dependent — each step works on the result of the previous.
ls -la | grep ".log" # list files, then filter for .log files
ps aux | grep "Safari" # list processes, then filter for Safari
cat errors.txt | sort | uniq # read file, sort lines, remove duplicates
Use backticks to control execution order
Backticks ` execute the inner command first and insert its output into the outer command. Use $() as the modern equivalent — same behavior, easier to nest.
echo "Hostname: `hostname`" # execute hostname first, embed result
chmod +x `find . -name "*.sh"` # find all .sh files first, then make them executable
echo "Today is $(date +%Y-%m-%d)" # modern syntax with $()
rm $(cat files-to-delete.txt) # delete files listed in a file
FileVault and Security
Get Status
FileVault status
fdesetup - FileVault configuration tool
fdesetup status
Check Secure Token users
sysadminctl
sysadminctl -secureTokenStatus jschlaht
Gatekeeper status
spctl - SecAssessment system policy security
spctl --status
System Integrity Protection (SIP) status
csrutil – Configure system security policies
csrutil status
Cleanup Tools & Reset Commands
Clear Cache
Flush DNS cache
dscacheutil – gather information, statistics and initiate queries to the Directory Service cache.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Clear user/system cache
rm -rf ~/Library/Caches/*
sudo rm -rf /Library/Caches/*
Reset processes and systems
Reset printing system
sudo rm -r /System/Library/Printers/
sudo rm -r /Library/Printers/