Mac CMD Command: Open Terminal & Use It
In this article
On a Mac there is no cmd command the way there is on Windows. The macOS equivalent is Terminal, the built-in app that gives you a Unix shell (zsh by default). If you type cmd into Terminal you will get zsh: command not found: cmd. To get the same result as opening Command Prompt on Windows, open Terminal from Applications > Utilities, or press Command+Space, type Terminal, and press Return. From there you can run standard Unix commands such as ls, cd, pwd, mkdir, cp, mv, rm, and sudo for administrator tasks.
What You'll Need
- A Mac running a current version of macOS (the steps below work on recent releases; menu labels can differ slightly by version and region).
- An administrator account if you plan to use
sudoor change system-level settings. - Basic familiarity with typing commands and pressing Return to run them.
Step-by-Step
- Open Terminal. Use Spotlight (Command+Space), type
Terminal, and press Return. Alternatively, open Finder, go to Applications > Utilities, and double-click Terminal. You can also pin Terminal to the Dock by right-clicking its icon and choosing Options > Keep in Dock. - Understand the prompt. You will see something like
username@MacBook ~ %. The%means the shell is zsh and ready for a command. The~shows you are in your home folder. - Check where you are. Type
pwdand press Return. It prints the full path of your current folder, for example/Users/yourname. - List files. Type
lsand press Return to see the contents of the current folder. Usels -lfor a detailed list with sizes and dates, orls -ato include hidden files. - Change folders. Type
cd Desktopto move into your Desktop folder, orcd ..to go up one level. Typecdalone to return to your home folder. - Create a folder. Type
mkdir testfolderand press Return. A new folder calledtestfolderappears in the current directory. Verify withls. - Create a file. Type
touch notes.txtto create an empty file. To write text into it, usenano notes.txt, type your text, then press Control+O, Return to save, and Control+X to exit. - Copy, move, and rename.
cp notes.txt copy.txtmakes a copy.mv copy.txt renamed.txtrenames it.mv renamed.txt testfolder/moves it into the folder you created. - Read a file. Type
cat notes.txtto print its contents in the Terminal window. For long files, useless notes.txtand press Q to quit. - Remove a file or folder.
rm notes.txtdeletes a file.rm -r testfolderdeletes a folder and everything inside it. There is no Trash and no undo, so double-check the name before pressing Return. - Run a command as administrator. Prefix it with
sudo, for examplesudo nano /etc/hosts. You will be asked for your login password; typing it shows no characters, which is normal. Press Control+X to exit the editor when done. - Close Terminal. Type
exitand press Return, or press Command+Q. Closing the window ends the shell session.
Common Mistakes
- Typing Windows commands.
dir,cls,copy, andcmddo not exist on macOS. Usels,clear, andcpinstead. - Forgetting spaces. Commands and their options need spaces:
ls -l, notls-l. - Using
rm -rcarelessly. It permanently deletes folders and their contents. Never run it on a path you have not checked withlsfirst. - Assuming
sudois always needed. Most everyday commands work without it. Use it only when a command fails with a permission error and you understand what the command does. - Pasting commands from the web without reading them. A command can delete files or change settings. Read it first, especially anything with
sudoorrm.
Tips
- Press Tab to auto-complete file and folder names, which reduces typos.
- Press the Up arrow to recall previous commands.
- Press Control+C to cancel a command that is running or stuck.
- Use
man ls(ormanplus any command) to read its manual; press Q to exit. - Drag a file from Finder into the Terminal window to insert its full path automatically.
- Keep a note of any command that changes system files, so you can reverse it if needed.
Troubleshooting
command not found: Check spelling and spacing. If the command is a tool you installed, confirm it is on your PATH; reinstalling the tool from its official source usually fixes it.Permission denied: The file or folder is read-only for your user. Confirm you are in the right folder withpwdandls -l, and only usesudoif the task genuinely requires administrator rights.- Terminal opens but shows a strange prompt: Quit Terminal (Command+Q) and reopen it. If the problem persists, check that your shell configuration file (such as
~/.zshrc) has not been edited incorrectly; restore a backup or remove the last change. - A command seems frozen: Press Control+C to interrupt it. If that does not work, close the Terminal window and open a new one.
- You deleted something by mistake: Terminal deletions do not go to the Trash. Check whether you have a backup (Time Machine or iCloud Drive) and restore from there.
- You need to reset Terminal to defaults: Quit Terminal, then reopen it while holding the Shift key to start a fresh session, or remove custom settings from Terminal > Settings. This does not delete your files.
Frequently Asked Questions
Is there a cmd command on Mac?
No. macOS uses Terminal with a Unix shell. The closest equivalent to Windows Command Prompt is the Terminal app, and the commands are Unix commands such as ls and cd.
How do I open Terminal quickly?
Press Command+Space, type Terminal, and press Return. You can also open Finder > Applications > Utilities > Terminal.
Can I run Windows .bat or .cmd files on a Mac?
Not natively. Those files are written for Windows. You would need a virtual machine or a compatibility layer, and even then some commands will not work.
What is sudo and when should I use it?
sudo runs a single command with administrator privileges. Use it only when a command needs to change system-level files or settings, and only after you understand what the command does.
Does Terminal have a Trash?
No. Files deleted with rm are gone immediately. Recover them from a backup if you have one.
Can I change the default shell?
Yes. macOS includes zsh and bash. You can change your login shell in System Settings > Users & Groups (the exact label varies by macOS version) or with the chsh command. Leave the default unless you have a specific reason to change it.