Introduction / Why This Is Useful
Terminal is a built-in macOS application for interacting with the system via text commands. Instead of a graphical interface, you manage files, launch programs, and perform complex operations with a single line of text. This skill unlocks access to powerful development, administration, and automation tools that aren't available through Finder.
After completing this guide, you'll be able to confidently navigate the command line, perform basic file and folder operations, and independently find solutions for more complex tasks.
Requirements / Preparation
- Hardware: Any Mac with macOS 10.12 Sierra or newer.
- Permissions: Standard user permissions are sufficient for most operations. System actions (e.g., modifying protected files) require administrator privileges (use
sudo). - Pre-installed Packages: Terminal uses the
zshshell (default in macOS since Catalina). All commands in this guide are compatible with bothzshandbash. - Security: Avoid running unknown commands with administrator privileges. Work in test folders (e.g.,
~/Documents/test) to prevent accidental deletion of system files.
Step 1: Opening Terminal and Getting Familiar with the Interface
Terminal is located in the Utilities folder inside the Applications folder. The fastest way to open it:
- Press
Cmd+Spaceto launch Spotlight. - Type
Terminaland pressEnter.
Terminal Interface:
- Command prompt: By default, it looks like
username@hostname ~ %. The%symbol (or$in bash) indicates that Terminal is ready for a command. - Terminal window: Command output appears here. You can open multiple tabs (
Cmd+T) or split the window (menu Terminal → Split Tab). - Menu: The top panel contains settings (font, colors, profiles). To start, use the Basic profile (menu Terminal → Settings).
💡 Tip: Adjust comfortable colors and font size in Settings → Profiles to reduce eye strain.
Step 2: Navigating the File System
Before working, it's important to understand your current location. The macOS file system is similar to Linux/Unix: root /, home folder ~ (short for /Users/your_name).
2.1. Viewing the Current Folder
pwd
Example output: /Users/ivan/Documents — the full path to the current directory.
2.2. Listing Files and Folders
ls
Shows the contents of the current folder. Add flags:
ls -l— detailed list (permissions, size, date).ls -a— show hidden files (those starting with.).
2.3. Moving Between Folders
cd path_to_folder
Examples:
cd ~/Documents # Navigate to the Documents folder in your home directory
cd .. # Move up one level
cd / # Go to the disk root
cd # Without arguments — return to your home folder (~)
⚠️ Important: Paths are case-sensitive.
Documents≠documents. Use Tab for autocompleting folder names.
Step 3: Managing Files and Folders
3.1. Creating a Folder
mkdir folder_name
Example: mkdir projects will create a projects folder in the current directory.
3.2. Creating an Empty File
touch file_name
Example: touch notes.txt creates a text file. You can create multiple files: touch a.txt b.txt.
3.3. Copying
cp source destination
- File:
cp file.txt backup.txt - Folder (recursively):
cp -r folder1 folder2
3.4. Moving or Renaming
mv old_path new_path
Examples:
mv old.txt new.txt # Rename a file
mv file.txt ~/Documents/ # Move a file
3.5. Deleting
rm file_name # Delete a file
rm -r folder_name # Delete a folder and all its contents
⚠️ Caution: Deletion via
rmdoes not move items to the Trash! Verify the command before executing.
Step 4: Viewing and Editing Files
4.1. Quick Content Preview
cat file_name
Outputs the entire file at once. For large files, use less:
less file_name
Controls in less:
Space— next page.b— previous page.q— quit.
4.2. Editing Simple Text
The built-in nano editor is simple for beginners:
nano file_name
- Write text, use
Ctrl+O(save),Ctrl+X(exit). - Hints at the bottom:
^meansCtrl.
4.3. Searching Within Files
grep "search_text" file_name
Example: grep "error" log.txt finds lines containing the word "error".
Step 5: Getting Help and Further Learning
5.1. Standard Help
command --help
Example: ls --help shows all ls command flags.
5.2. Detailed Manual (man Pages)
man command
Example: man mkdir opens documentation with descriptions, options, and examples. Scroll with arrows, search (/text), quit (q).
5.3. Command History
Press ↑/↓ to scroll through previously executed commands. Or view the full journal:
history
To execute a command from history by number: !number (e.g., !42).
5.4. Autocompletion
Start typing a command or path and press Tab. Terminal will suggest options. If multiple options exist, press Tab twice to display the list.
Verification
You've successfully mastered the basics if you can:
- Open Terminal and run
pwdto see the current folder. - Navigate to another folder via
cdand return. - Create a
test_projectfolder and areadme.mdfile inside it. - Find the word "project" in
readme.mdusinggrep. - Open
readme.mdinnano, add text, and save.
Example verification sequence:
pwd
cd ~/Documents
mkdir test_project
cd test_project
touch readme.md
echo "My first project" > readme.md
grep "project" readme.md
nano readme.md # add a line and save (Ctrl+O, Ctrl+X)
If all steps completed without errors, you're ready for independent work.
Potential Issues
5.1. Permission denied Error
Cause: No write/delete permissions in the current folder (e.g., a system folder). Solution:
- Navigate to a folder where you have permissions (e.g.,
~/Documents). - For system operations, use
sudo(administrator password required). Example:sudo rm protected_file. Be careful withsudo!
5.2. Command not found Error
Cause: The command doesn't exist or isn't installed (e.g., a Homebrew utility). Solution:
- Check for typos.
- Ensure the command is installed (e.g.,
gitrequires Xcode Command Line Tools:xcode-select --install).
5.3. No such file or directory Error
Cause: Incorrect path or filename. Solution:
- Check the current folder (
pwd) and contents (ls). - Use autocompletion (Tab) for file/folder names.
- Ensure the path is correct (relative to current folder or absolute).
5.4. Interface "Freezes" or Doesn't Respond
Cause: A long-running process (e.g., cat on a large file) or waiting for input.
Solution:
- Press
Ctrl+Cto interrupt the current command. - If Terminal is completely unresponsive, close and reopen the window (unsaved data in that window will be lost).
5.5. Difficulties with Paths Containing Spaces
Cause: Spaces in file/folder names split the path into parts. Solution: Enclose the path in quotes or escape the space with a backslash:
cd "Folder with a space"
cd Folder\ with\ a\ space