How to Use CMD on Mac: Terminal Basics
In this article
You cannot run CMD (Command Prompt) on a Mac because CMD is a Windows program; macOS has its own command-line tool called Terminal, which works similarly for most everyday tasks. To get started, open Terminal from Applications > Utilities (or search with Spotlight), type a command, and press Return. This guide walks you through the basics safely, explains where Mac commands differ from Windows CMD, and covers common mistakes and fixes.
What You'll Need
- A Mac running a current version of macOS (the steps below apply to recent releases; labels can differ slightly by version).
- An administrator account if you plan to run commands that require elevated permissions (you will be asked for your password).
- A backup of important files before running unfamiliar commands, especially anything that deletes or moves data.
Step-by-Step
- Open Terminal. Go to Applications > Utilities > Terminal. Alternatively, press Command+Space to open Spotlight, type Terminal, and press Return. Terminal opens with a prompt showing your computer name and username.
- Understand the prompt. The line ending with
$or%is where you type. The text before it shows your username and current folder. You do not type the prompt itself. - Run a simple command. Type
pwdand press Return. This prints your current directory (folder). It is a safe way to confirm Terminal is working. - List files. Type
lsand press Return to see the contents of the current folder. Add-lfor a detailed list (ls -l). - Change folders. Use
cdfollowed by a folder name. For example,cd Documentsmoves into your Documents folder. Typecd ..to go up one level. Typecd ~to return to your home folder. - Create a folder. Type
mkdir testfolderand press Return. This creates a new folder called testfolder in the current directory. You can verify withls. - View file contents. Use
cat filename.txtto print a file's contents to the screen. For longer files, useless filename.txtto scroll (press Q to quit). - Copy, move, and delete files. Use
cp source.txt destination.txtto copy,mv oldname.txt newname.txtto rename or move, andrm filename.txtto delete. Be careful withrm; deleted files do not go to the Trash. - Get help. Most commands have a manual page. Type
man ls(or another command name) and press Return to read usage details. Press Q to exit the manual. - Clear the screen. Type
clearand press Return to tidy the window without deleting anything. - Close Terminal. Type
exitand press Return, or close the window with Command+W. Closing Terminal does not undo changes you made with commands.
Common Mistakes
- Typing Windows commands. Commands like
dir,copy, anddelare not native macOS commands. Usels,cp, andrminstead. - Running commands without understanding them. Some commands, especially
rm -rf, can delete files permanently. Read the manual page first and double-check the path. - Forgetting spaces. Commands and their options need spaces.
ls-lwill not work; usels -l. - Using sudo unnecessarily.
sudoruns a command with administrator privileges and can change system files. Only use it when a trusted guide specifically says to, and never copy-paste commands you do not understand. - Assuming Terminal and CMD are identical. Many concepts are similar, but syntax and available tools differ. Check Mac-specific instructions.
Tips
- Use Tab completion: type the first few letters of a file or folder name and press Tab to auto-complete it.
- Press the Up Arrow to recall previous commands, saving typing and reducing errors.
- Drag a file or folder into the Terminal window to insert its full path automatically.
- Keep a note of commands that work for you; Terminal does not have a built-in undo for file operations.
- If you need Windows CMD specifically, you must use a virtual machine or remote desktop to a Windows PC; macOS does not include CMD.
Troubleshooting
- Command not found: Check spelling and capitalization. macOS commands are case-sensitive. If the command is from a third-party tool, it may not be installed.
- Permission denied: You may need to prefix the command with
sudo(for administrator actions) or adjust file permissions. Be cautious withsudo. - Terminal won't open: Restart your Mac. If the issue persists, check for macOS updates or create a new user account to test.
- Accidentally deleted a file: Check the Trash first; files deleted with
rmdo not go there. Restore from a backup if available. - Stuck in a command: Press Control+C to cancel the current command and return to the prompt.
Frequently Asked Questions
Can I run CMD on a Mac?
No, CMD is a Windows program. macOS includes Terminal, which serves the same purpose. To run CMD itself, you would need Windows running in a virtual machine or on a separate PC.
Is Terminal the same as CMD?
They are similar in concept but use different command languages. Many basic tasks like listing files or changing folders have different commands. Terminal uses Unix-style commands.
How do I open Terminal quickly?
Use Spotlight (Command+Space) and type Terminal, then press Return. You can also find it in Applications > Utilities.
Is it safe to use Terminal?
Terminal is safe for standard commands, but commands that delete or modify files can cause permanent changes. Always understand a command before running it, and keep backups.
How do I stop a command that is running?
Press Control+C to interrupt the current process and return to the prompt.
Can I use Terminal to manage smart home devices?
Not directly. Smart home devices are typically controlled through their apps or voice assistants. Terminal is for local system tasks, not for controlling devices unless you are using a specific developer tool, which is outside typical use.