Expanding Your Command-Line Arsenal: Essential Commands for MacOS IT Admins

Kushal Pokhrel
4 min readAug 22, 2024

--

This article provides a comprehensive guide to essential command-line tools and techniques for Mac IT administrators. It covers many topics, including network management, system configuration, process management, security, and automation. By mastering these commands, you can enhance your ability to manage your Mac fleet efficiently and effectively. The article includes practical examples and explanations to help you apply the knowledge to your daily tasks.

Photo by Tyler Franta on Unsplash

Introduction:

In today’s rapidly evolving technological landscape, IT administrators play a crucial role in ensuring the smooth operation and security of organizational networks. For those managing a fleet of Mac devices, mastering the command line interface (CLI) is essential. The CLI provides a powerful and efficient way to interact with your system, offering granular control, automation capabilities, and the ability to perform tasks that are difficult or impossible with the graphical user interface (GUI).

This comprehensive guide will equip you with a robust set of command-line tools and techniques to enhance your Mac administration skills. We’ll delve into essential commands for network management, system configuration, process management, security, and automation. By the end of this article, you’ll be able to confidently navigate the command line and leverage its full potential to optimize your Mac fleet.

Network Management

  • ifconfig: Displays network interface information.
  • Example: ifconfig en0 (to display information about the Ethernet interface)
  • ping: Tests network connectivity to a specific host.
  • Example: ping google.com (to ping Google's DNS servers)
  • netstat: Displays network statistics and connections.
  • Example: netstat -l (to list listening TCP and UDP ports)
  • dig: Resolves domain names to IP addresses.
  • Example: dig google.com (to resolve the IP address of google.com)
  • nc: Opens network connections.
  • Example: nc google.com 80 (to connect to Google's web server on port 80)

System Information and Configuration

  • system_profiler: Provides detailed system information.
  • Example: system_profiler SPHardwareDataType (to get hardware information)
  • defaults: Reads and writes system preferences.
  • Example: defaults read com.apple.finder NewWindowTarget (to get the default location for new Finder windows)
  • dscacheutil: Manages directory service caches.
  • Example: dscacheutil -flushcache (to flush the directory service cache)
  • softwareupdate: Checks for and installs software updates.
  • Example: softwareupdate -l (to list available updates)
  • diskutilmanages disc volumes and partitions.
  • Example: diskutil list (to list available disc volumes)

Process Management

  • top: Displays a list of running processes.
  • Example: top -u your_username (to show processes belonging to your user)
  • ps: Lists running processes.
  • Example: ps aux (to list all processes)
  • kill: Terminates a process.
  • Example: kill -9 1234 (to kill process with PID 1234)
  • nice: Sets the priority of a process.
  • Example: nice -n 19 top (to run top with low priority)
  • launchctlmanages launched jobs.
  • Example: launchctl list (to list launched jobs)

Security and User Management

  • sudo: Executes commands with superuser privileges.
  • Example: sudo passwd root (to change the root password)
  • passwd: Changes passwords.
  • Example: passwd your_username (to change your own password)
  • users: Lists users on the system.
  • Example: users (to list active users)
  • authorizationmanages authorisation policies.
  • Example: authorization -w /Library/Authorization/Rules/com.apple.loginwindow.plist (to write to the loginwindow authorisation rule)
  • security: Provides security-related functions.
  • Example: security unlock-keychain -p your_password (to unlock the default keychain)

Scripting and Automation

  • bash: The default shell on macOS.
  • zsh: A popular alternative shell with advanced features.
  • python: A versatile scripting language.
  • ruby: Another popular scripting language.
  • applescript: Apple's scripting language for automating GUI applications.

Example: Checking Disc Space in Bash

#!/bin/bash
# Get the disc usage of the root volume
diskutil info | grep "Total:" | awk '{print $3}'
Check if the disc usage exceeds 80%
if [ $(diskutil info / | grep "Total:" | awk '{print $3}') -gt 80 ]; then
echo "Disc usage is high. Consider freeing up space."
fi

Remember to replace placeholders your_username with your actual values.

Photo by Daniel Korpai on Unsplash

Conclusion:

By mastering the command-line tools and techniques outlined in this guide, you’ll be well-equipped to manage your Mac fleet efficiently and troubleshoot various issues. The CLI offers a level of control and flexibility that is simply unmatched by the GUI. Whether you’re automating repetitive tasks, diagnosing system problems, or implementing security measures, the command line is an invaluable tool for any Mac IT administrator.

Remember to practice regularly and experiment with different commands to solidify your understanding and build your skills.

References:

Execute commands and run tools in Terminal on Mac. (2024). Apple Support. https://support.apple.com/en-au/guide/terminal/apdb66b5242-0d18-49fc-9c47-a2498b7c91d5/mac

Get started with Terminal on Mac. (2024). Apple Support. https://support.apple.com/en-au/guide/terminal/pht23b129fed/mac

--

--

Kushal Pokhrel
Kushal Pokhrel

Written by Kushal Pokhrel

Google Developer Expert, Machine Learning • Sessional Lecturer • AI/ML Researcher

No responses yet