Introduction / Why This Is Useful
The Terminal in macOS is a powerful tool for system management, software installation, task automation, and troubleshooting issues not accessible through the graphical interface. Even basic command-line skills will significantly boost your efficiency as a Mac user. After this guide, you'll be able to confidently navigate the filesystem, view and create files, and execute basic system commands.
Requirements / Preparation
Before starting, ensure you have:
- macOS version 10.15 (Catalina) or newer installed (instructions are relevant for Sonoma, Ventura, Monterey).
- Access to an account with standard privileges (administrator rights are not required for most basic operations in your home folder).
- The Terminal utility — it comes preinstalled on all macOS versions and is located in
/Applications/Utilities/Terminal.app.
Step 1: Open Terminal and Understand the Interface
- Open Terminal using one of these methods:
- Press
Cmd + Spaceto launch Spotlight, typeterminal, and pressEnter. - Open Finder, go to the Applications → Utilities folder, and double-click Terminal.
- Use Launchpad (the icon in the Dock) and find the app among the others.
- Press
- After launching, you'll see a window with a black (or light, depending on your profile) background and a line that looks like this:
user@MacBook-Pro ~ %user— your username in the system.MacBook-Pro— your computer name (can be changed in System Settings → General → About This Mac).~(tilde) — represents your home directory (/Users/your_username). This is your current location.%— this is the command prompt. In bash-based systems (standard for macOS before Catalina), it's%for regular users and#for root. In newer versions (using zsh by default), it's%or$.
- The cursor blinks after
%. Everything you type will be interpreted as a command. Use only Latin letters and symbols when typing commands; the Russian keyboard layout can cause errors.
Step 2: Basic Filesystem Navigation Commands
Understand your current location before running commands.
- Show the current path (
pwd). Type the command and pressEnter:pwd
Terminal will output the full path to the current directory, for example:/Users/john - View contents of the current folder (
ls).ls
By default, it shows only file and folder names. For a more detailed output (permissions, owner, size, date), use the-lflag:ls -l - Change to another folder (
cd— change directory).- Change to the
Documentsfolder (create it in Finder beforehand if it doesn't exist):cd Documents - Go back to the previous directory (one level up):
cd .. - Return directly to your home directory (from anywhere):
or simplycd ~cd
- Change to the
- Autocomplete (Tab).
When typing a folder or file name, press the
Tabkey. Terminal will automatically complete the name if it's unambiguous. If there are multiple matches, pressTabtwice to see them. This saves time and prevents typos.
Step 3: Practice: Creating and Working with Files
Let's practice by creating a temporary structure.
- Create a new folder (
mkdir— make directory). Ensure you're in your home directory (cd ~). Create a folder namedterminal_test:mkdir terminal_test - Navigate into the created folder and create a file (
touch).cd terminal_test touch notes.txt
Thenotes.txtfile will be created empty. - Write text to a file (output redirection).
The simplest way is to use the
echocommand and the>symbol (redirect output to a file):echo "Hello, Terminal!" > notes.txt
Note:>overwrites the file if it already exists. To append text to the end of a file, use>>. - View file contents (
cat).cat notes.txt
The stringHello, Terminal!will appear on the screen. - Delete a file and a folder (
rmandrmdir).- Delete the file:
rm notes.txt - Go up one level and delete the empty folder:
cd .. rmdir terminal_test - Caution! The
rmcommand without flags deletes files permanently (they don't go to the Trash). To delete non-empty folders, userm -r <folder_name>. Be extremely careful withrm, especially withsudo rm -rf /.
- Delete the file:
Step 4: Useful Utilities for Daily Use
clear— clear the terminal screen (same asCmd + K).history— show a list of commands you've entered.man <command>— open detailed documentation (manual) for any command. Pressqto exit the manual.man lsCtrl + R— search through command history. Start typing part of a command, and Terminal will find the most recent match.
Step 5: Ending Your Terminal Session
- To close the terminal window, simply close it (the X in the corner) or type
exitand pressEnter. All processes running in that window will terminate. - If you connected to a remote server via SSH, use
exitorCtrl + Dto disconnect. - Do not use commands like
sudo shutdown -h nowor other system commands to shut down your Mac from the terminal unless absolutely necessary. Use graphical methods for that.
Checklist
You've successfully learned the basics if you can:
- Open Terminal and understand where you are (using
pwd). - Navigate to another folder (
cd) and go back. - View a list of files (
ls). - Create a folder (
mkdir), create a file inside it (touch), write text to it (echo >). - Read file contents (
cat) and delete it (rm). - Safely end your session (
exitor closing the window).
Common Issues
command not found: The command was typed incorrectly or doesn't exist. Check spelling. Ensure you're not trying to run a Linux-only command (e.g.,apt).Permission denied: You lack sufficient permissions for the operation (e.g., writing to a system folder). Don't try to bypass this withsudounless you understand the consequences. Work within your home directory (/Users/your_username).No such file or directory: The specified file or folder wasn't found at the given path. Check your current directory (pwd) and the name's accuracy (case matters:Folderandfolderare different names in Unix systems).- Terminal "freezes": You launched an interactive program (e.g.,
top,vim,ssh). To exit, useCtrl + C(interrupt) orCtrl + D(end input/exit). If that doesn't work, close the terminal window. - Cyrillic in paths or filenames: The macOS command line (zsh/bash) primarily uses UTF-8, but some older utilities may not handle Cyrillic correctly. Try to use Latin names for folders and files you plan to work with from the terminal.