Mac Os X Command Line Cheat Sheet

5 min read

Mac OS X Command Line Cheat Sheet

The macOS command line, accessible through the Terminal application, is one of the most powerful tools available to every Mac user. Whether you are a beginner looking to speed up everyday tasks or an experienced developer managing servers remotely, knowing essential commands can dramatically improve your productivity. This macOS command line cheat sheet covers the most useful commands organized by category, helping you manage, manage files, troubleshoot network issues, and control processes directly from the keyboard. Mastering these commands gives you fine-grained control over your system that graphical interfaces simply cannot match The details matter here. That alone is useful..


Understanding the macOS Command Line

Before diving into specific commands, it helps to understand what the command line actually is. The Terminal app on macOS provides a text-based interface to your operating system. Behind the scenes, macOS is built on a Unix foundation, which means it shares many commands with Linux and other Unix-like systems. When you type a command and press Enter, the shell — typically zsh in modern macOS versions — interprets your input and executes it Practical, not theoretical..

You can open Terminal by navigating to Applications > Utilities > Terminal, or by using Spotlight search with Command + Space and typing "Terminal." Once open, you will see a prompt that typically displays your username, the machine name, and your current directory Which is the point..


Essential Navigation Commands

Navigating through your file system is the first skill every user should learn. These commands let you move between directories and understand where you are at any given moment.

  • pwd — Prints your current working directory. This is useful when you lose track of where you are in the file system.
  • ls — Lists files and folders in the current directory. Add -la to see hidden files, file sizes, permissions, and modification dates.
  • cd — Changes the current directory. Use cd Documents to enter a folder, cd .. to go up one level, and cd ~ to return to your home directory.
  • cd - — Takes you back to the previous directory you were in, acting like a "back" button.
  • tree — Displays a visual tree of directories and subdirectories. If not installed by default, you can add it via Homebrew with brew install tree.

These navigation commands form the backbone of daily command line usage. Practicing them until they become second nature will make every other command easier to learn It's one of those things that adds up. Surprisingly effective..


File Management Commands

Working with files and directories efficiently is one of the biggest reasons users turn to the command line. Here are the commands you need in your macOS command line cheat sheet for file management Small thing, real impact..

  • mkdir filename — Creates a new directory. Use mkdir -p path/to/nested/folder to create multiple levels at once.
  • touch filename — Creates an empty file or updates the timestamp of an existing file.
  • cp source destination — Copies a file or directory. Add -R to copy entire folders recursively.
  • mv source destination — Moves or renames a file. Here's one way to look at it: mv oldname.txt newname.txt renames the file.
  • rm filename — Removes a file permanently. Use rm -r directory to delete a folder and all its contents. Be extremely careful with this command, as there is no Trash recovery.
  • rmdir directory — Removes an empty directory only.
  • ln -s target linkname — Creates a symbolic link, essentially a shortcut to a file or folder elsewhere on your system.

Always double-check your targets before running copy, move, or delete commands. A small typo can result in lost data Not complicated — just consistent. Surprisingly effective..


System Information Commands

When you need to learn about your Mac's hardware, software, or system status, these commands provide instant answers Worth keeping that in mind..

  • uname -a — Displays detailed system information including kernel name, version, and architecture.
  • sw_vers — Shows your macOS version, build number, and kernel version.
  • system_profiler SPSoftwareDataType — Provides a detailed software overview. Replace the data type to get hardware, network, or other specifics.
  • top — Displays real-time CPU and memory usage for all running processes. Press q to quit.
  • uptime — Shows how long your Mac has been running and the current load averages.
  • df -h — Displays disk space usage in a human-readable format.
  • free -m — Shows memory usage in megabytes (note: on newer macOS, use vm_stat instead).

These system commands are invaluable for troubleshooting performance issues or verifying system specifications before installing software.


Network Commands

Network troubleshooting is another area where the command line shines. These commands help diagnose connectivity problems and monitor network activity.

  • ifconfig — Displays network interface configurations including IP addresses. On newer macOS versions, ipconfig getifaddr en0 gives you your local IP quickly.
  • ping hostname — Sends packets to a host to test connectivity. Add -c 10 to limit the number of pings.
  • traceroute hostname — Shows the path your data takes to reach a destination, identifying where delays occur.
  • netstat -an — Lists all active network connections and listening ports.
  • nslookup domain.com — Queries DNS records to resolve domain names to IP addresses.
  • curl URL — Downloads content from a URL directly to your terminal. Add -O to save the file with its original name.
  • wget URL — Similar to curl but not installed by default; can be added through Homebrew.

Having these network tools at your fingertips eliminates the need for third-party diagnostic apps in most situations.


Process Management Commands

Managing running processes allows you to keep your system responsive and terminate unresponsive applications without restarting.

  • ps aux — Lists all currently running processes with detailed information including CPU and memory usage.
  • top — Provides a dynamic, real-time view of system processes (as mentioned above).
  • kill PID — Sends a termination signal to a process using its Process ID. Use kill -9 PID for forceful termination when a process ignores normal stop requests.
  • killall ApplicationName — Kills all instances of an application by name. Take this: killall Safari closes all Safari windows.
  • lsof -i :port — Shows which process is using a specific network port, useful for debugging port conflicts.
  • bg and fg — Send a running process to the background or bring it back to the foreground.

These process commands are especially useful for developers running local servers or dealing with stuck applications.


Finder and Shortcut Commands

Some commands bridge the gap between the command line and the graphical Finder interface, making your workflow more seamless.

  • **

  • open — Opens files, directories, or applications just like double-clicking in Finder. Use open . to open the current directory in Finder, or open -a "TextEdit" file.txt to open a file with a specific application.

  • defaults write — Modifies macOS preference files directly. As an example, defaults write com.apple.finder AppleShowAllFiles YES reveals hidden files (requires Finder restart) Surprisingly effective..

  • **`qlmanage

Keep Going

Recently Shared

These Connect Well

Before You Head Out

Thank you for reading about Mac Os X Command Line Cheat Sheet. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home