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
- Open the Terminal
- On macOS/Linux: Press Ctrl+Alt+T or find the terminal app in your applications menu.
- 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.
- Navigate Folders
- Move up one folder:
cd ..(e.g., from "/home/user/Downloads" to "/home/user"). - Move to a specific folder:
cd Documents(orcd ~/Documentson macOS/Linux). - Create a new folder:
mkdir MyProjects(Linux/macOS). On Windows, usemkdir MyProjectsin Command Prompt orNew-Item -ItemType Directory -Name MyProjectsin PowerShell.
- Move up one folder:
- List Files and Directories
- List files/folders in current directory:
ls(macOS/Linux) ordir(Windows). - Show hidden files (e.g., system files):
ls -a(macOS/Linux) ordir /a(Windows).
- List files/folders in current directory:
- Copy, Move, and Delete Files
- Copy a file:
cp file.txt /path/to/destination(Linux/macOS). On Windows, usecopy file.txt C:\path\to\destinationin CMD orCopy-Item file.txt -Destination C:\path\to\destinationin PowerShell. - Move a file:
mv file.txt newlocation(Linux/macOS) ormove file.txt C:\path\to\newlocation(Windows). - Delete a file:
rm file.txt(Linux/macOS) ordel file.txt(Windows). Warning: Userm -i(Linux/macOS) ordel /q file.txt(Windows) to confirm deletion before committing.
- Copy a file:
- View File Contents
- Open a text file:
cat file.txt(Linux/macOS) ortype file.txt(Windows). - Search inside a file:
grep "search term" file.txt(Linux/macOS). On Windows, use PowerShell:Get-Content file.txt | Select-String "search term">
- Open a text file:
- Find and Switch Between Terminals
- Open a new terminal window:
gnome-terminal(Linux/macOS) orcmd(Windows). - Open a new tab in the current terminal: Press Ctrl+Shift+T (macOS/Linux) or Ctrl+Shift+N (Windows).
- Open a new terminal window:
Common Mistakes
- Typo errors: Terminal is case-sensitive ("ls" ≠ "Ls"). Always double-check paths (e.g.,
cd Documents, notcd documents). Usepwd(Linux/macOS) orecho $PWD(macOS/Linux) orcd $HOMEto 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) orcopy file.txt backup.txt /Y(Windows) to prevent accidental overwrites. - Running as Administrator: Some commands (e.g.,
sudo apt updateon Linux) require admin privileges. Usesudocarefully—it grants full system access.
Tips
- Use
tabfor autocompletion. For example, typecd Dothen presstabto completeDocuments. - 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).
- Linux/macOS:
- Store frequently used commands in
~/.bashrc(Linux/macOS) or%USERPROFILE%\Documents\TerminalShortcuts.txt(Windows). - For automation, learn basic shell scripts (e.g.,
.shfiles). Example:#!/bin/bash; echo "Hello, World!".
Troubleshooting
- Terminal won’t open:
- Restart your computer.
- 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. - Reinstall the terminal app (e.g., "Terminal.app" on macOS, "Windows Terminal" on Windows).
- Commands don’t work:
- Check your OS version: Some commands (e.g.,
ls) are deprecated in newer macOS versions. Usedirin Windows orfindfor search. - Update your system: Run
sudo apt update && sudo apt upgrade(Linux) orwinget upgrade --all(Windows). - Verify permissions: If you get "Permission denied," use
sudo(Linux/macOS) or run as Administrator (Windows CMD).
- Check your OS version: Some commands (e.g.,
- Files are missing after deletion:
- Check the Recycle Bin (Windows) or Trash folder (macOS/Linux).
- Use recovery tools (e.g.,
testdiskon Linux/macOS) or Windows File Recovery (Windows). - If the file was deleted via
rm, restore from backups or usegit recoverif 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.