The terminal command prompt is your powerful tool for controlling files, running programs, and automating tasks on your computer. With just a few key commands, you can save hours of manual work—no graphic user interface needed. This guide shows you the essential commands, how to use them safely, and what to do if things go wrong.

What You'll Need

  • A computer running a modern operating system (Windows 10/11, macOS, or Linux).
  • Access to a command-line interface (usually opened by pressing Ctrl+Alt+T on Linux/macOS, or Win+R and typing "cmd" on Windows).
  • Basic familiarity with folders and files (you’ll use paths like "C:\Users" or "/home/user").

Step-by-Step: Essential Terminal Commands

  1. Open the Terminal
    1. On macOS/Linux: Press Ctrl+Alt+T or find the terminal app in your applications menu.
    2. On Windows: Press Win+R, type "cmd", and hit Enter. For PowerShell (command-line alternative), use "powershell" instead.

    If you see a login prompt (e.g., "user@machine:~$"), you’re ready. If not, restart your computer or check your system settings.

  2. Navigate Folders
    1. Move up one folder: cd .. (e.g., from "/home/user/Downloads" to "/home/user").
    2. Move to a specific folder: cd Documents (or cd ~/Documents on macOS/Linux).
    3. Create a new folder: mkdir MyProjects (Linux/macOS). On Windows, use mkdir MyProjects in Command Prompt or New-Item -ItemType Directory -Name MyProjects in PowerShell.
  3. List Files and Directories
    1. List files/folders in current directory: ls (macOS/Linux) or dir (Windows).
    2. Show hidden files (e.g., system files): ls -a (macOS/Linux) or dir /a (Windows).
  4. Copy, Move, and Delete Files
    1. Copy a file: cp file.txt /path/to/destination (Linux/macOS). On Windows, use copy file.txt C:\path\to\destination in CMD or Copy-Item file.txt -Destination C:\path\to\destination in PowerShell.
    2. Move a file: mv file.txt newlocation (Linux/macOS) or move file.txt C:\path\to\newlocation (Windows).
    3. Delete a file: rm file.txt (Linux/macOS) or del file.txt (Windows). Warning: Use rm -i (Linux/macOS) or del /q file.txt (Windows) to confirm deletion before committing.
  5. View File Contents
    1. Open a text file: cat file.txt (Linux/macOS) or type file.txt (Windows).
    2. Search inside a file: grep "search term" file.txt (Linux/macOS). On Windows, use PowerShell: Get-Content file.txt | Select-String "search term">
  6. Find and Switch Between Terminals
    1. Open a new terminal window: gnome-terminal (Linux/macOS) or cmd (Windows).
    2. Open a new tab in the current terminal: Press Ctrl+Shift+T (macOS/Linux) or Ctrl+Shift+N (Windows).

Common Mistakes

  • Typo errors: Terminal is case-sensitive ("ls" ≠ "Ls"). Always double-check paths (e.g., cd Documents, not cd documents). Use pwd (Linux/macOS) or echo $PWD (macOS/Linux) or cd $HOME to verify you’re in the right folder.
  • Forgetting spaces: Commands like rmfile.txt (missing space) delete nothing—always include spaces between commands and arguments.
  • Overwriting files: Use cp -i file.txt backup.txt (Linux/macOS) or copy file.txt backup.txt /Y (Windows) to prevent accidental overwrites.
  • Running as Administrator: Some commands (e.g., sudo apt update on Linux) require admin privileges. Use sudo carefully—it grants full system access.

Tips

  • Use tab for autocompletion. For example, type cd Do then press tab to complete Documents.
  • Master these keystrokes:
    • Linux/macOS: Ctrl+O (save), Ctrl+X (cut), Alt+. (history), Ctrl+C (stop), Ctrl+V (paste).
    • Windows CMD: Ctrl+V (paste), Ctrl+Z (undo), Ctrl+Shift+V (paste as plain text).
  • Store frequently used commands in ~/.bashrc (Linux/macOS) or %USERPROFILE%\Documents\TerminalShortcuts.txt (Windows).
  • For automation, learn basic shell scripts (e.g., .sh files). Example: #!/bin/bash; echo "Hello, World!".

Troubleshooting

  1. Terminal won’t open:
    1. Restart your computer.
    2. Check for software conflicts: Run sudo lsof | grep terminal (Linux/macOS) or search for "Service Manager" (Windows) to see if the terminal service is disabled.
    3. Reinstall the terminal app (e.g., "Terminal.app" on macOS, "Windows Terminal" on Windows).
  2. Commands don’t work:
    1. Check your OS version: Some commands (e.g., ls) are deprecated in newer macOS versions. Use dir in Windows or find for search.
    2. Update your system: Run sudo apt update && sudo apt upgrade (Linux) or winget upgrade --all (Windows).
    3. Verify permissions: If you get "Permission denied," use sudo (Linux/macOS) or run as Administrator (Windows CMD).
  3. Files are missing after deletion:
    1. Check the Recycle Bin (Windows) or Trash folder (macOS/Linux).
    2. Use recovery tools (e.g., testdisk on Linux/macOS) or Windows File Recovery (Windows).
    3. If the file was deleted via rm, restore from backups or use git recover if you’re using version control.

Frequently Asked Questions

How do I switch between terminals on macOS/Linux?

Use Ctrl+Alt+T to open a new terminal. If you’re in a script, you can create multiple terminals by running gnome-terminal in Bash or konsole --workspace 1 in KDE.

What if I get a "command not found" error?

This means the command isn’t installed or isn’t in your system’s PATH. Update your system (e.g., sudo apt upgrade on Debian-based Linux) or add the command to your PATH (e.g., export PATH=$PATH:/path/to/new/dir). For Windows, reinstall the command (e.g., Git Bash, WSL).

Can I use the terminal in Windows without admin rights?

No. Some commands (e.g., sudo, sc.exe, or system registry edits) require admin privileges. To avoid this, use PowerShell with RunAsAdministrator or switch to a user account with admin access.

How do I save my terminal history?

On macOS/Linux, save history to ~/.bash_history or ~/.zsh_history. On Windows CMD, history is saved to cmdhistory.txt in C:\Windows\System32\cmdhistory.txt. To prevent accidental overwrites, use history -a (Linux/macOS) or type cmdhistory.txt >> oldhistory.txt (Windows).

What’s the difference between cp and mv in Linux/macOS?

cp copies files/folders, while mv moves them. Both can rename files, but mv is faster for moving large files or directories.

Can I use the terminal in a browser?

No. The terminal is a native command-line interface for your OS, not a web browser. Use online terminals (e.g., Repl.it) only for learning—sensitive commands won’t work securely in untrusted environments.