The command line (also called the terminal) gives you direct control over your computer’s operating system, letting you automate tasks, manage files, and solve problems faster than with a graphical interface.
What You'll Need
- A computer running Windows (with Windows Subsystem for Linux or built-in Command Prompt/PowerShell), macOS (Terminal.app), or Linux (GNOME Terminal, Konsole, etc.).
- Basic typing skills (no advanced coding knowledge required).
- An internet connection (only needed for downloading tools or updating software).
- Optional: A text editor like VS Code or Notepad++ if you’ll be writing scripts later.
Step-by-Step
-
Open your terminal:
- Windows: Press Win + R, type `cmd` (for Command Prompt) or `powershell` (for PowerShell), then hit Enter. For Linux/macOS support, install Windows Subsystem for Linux (WSL).
- macOS/Linux: Press Cmd + Space to open Spotlight/Applications Search, type `Terminal`, and hit Enter.
-
Identify your prompt:
The terminal opens with a cursor and text like:
$(macOS/Linux) orC:\Users\YourName>(Windows Command Prompt). PowerShell usesPSinstead of$. -
Master basic navigation:
- List files: Type
ls(macOS/Linux) ordir(Windows) to see directory contents. - Change directories: Use
cd+ a folder name (e.g.,cd Documents). Go up one level withcd ... - Check your current path: Type
pwd(macOS/Linux) orecho %cd%(Windows).
- List files: Type
-
Run simple commands:
- Create a file: Type
touch newfile.txt(macOS/Linux) orecho. > newfile.txt(Windows). - Delete a file: Use
rm file.txt(macOS/Linux) ordel file.txt(Windows). - View file contents: Type
cat file.txt(macOS/Linux) ortype file.txt(Windows).
- Create a file: Type
-
Use wildcards and shortcuts:
- Replace text with * (e.g.,
ls *.txtlists all `.txt` files). - Use Tab to auto-complete folder names or commands.
- Press ↑ or ↓ to scroll through previous commands.
- Replace text with * (e.g.,
- Edit commands interactively: Hold Ctrl + U to delete text before the cursor (or Ctrl + K to delete after). Press Ctrl + R to search through command history (type part of the command, then Enter).
-
Close the terminal:
Type
exit(macOS/Linux) orclose(Windows), then press Enter. On Windows, you can also close the window with the X button.
Common Mistakes
-
Ignoring case sensitivity:
Commands like
Ls(uppercase) won’t work—always use lowercase unless specified (e.g., some Windows tools accept mixed case). -
Forgetting paths:
If a command fails, double-check if you’re in the correct directory (use
pwdorecho %cd%). -
Not checking errors:
Red text often indicates a mistake (e.g., "Permission denied" means you lack access). Use
man [command](macOS/Linux) orhelp(Windows) for help. -
Mixing Windows and Unix commands:
Avoid
rm -rfon Windows (it doesn’t exist). Usedel /s /qcarefully instead.
Tips
-
Use aliases:
Create shortcuts for frequent commands. For example, in macOS/Linux, add this to your `~/.bashrc` file:
alias ll='ls -la'Then reload withsource ~/.bashrc. -
Pipe commands:
Combine actions with
|(e.g.,ls | grep "file"lists only files containing "file"). -
Save commands for later:
In macOS/Linux, type
historyto see past commands. Copy and paste them into a text file for reference. -
Learn keyboard shortcuts:
Ctrl + C stops a running command; Ctrl + Z pauses it (then use
fgto resume). -
Explore built-in help:
Type
help(Windows) orman [command](macOS/Linux) to access documentation directly.
Troubleshooting
If something goes wrong:
- Restart your terminal: Close and reopen the terminal window. This clears minor glitches.
-
Check your spelling:
Typos (e.g.,
lssinstead ofls) cause errors. Use Tab auto-complete to avoid mistakes. -
Verify file permissions:
If you get "Permission denied," use
sudo(Linux/macOS) or run Command Prompt as Administrator (Windows). Warning: Only usesudowhen necessary—it grants root-level access. -
Update your system:
Outdated tools may fail. On macOS, run
sudo softwareupdate -i -a. On Windows, update via Settings > Windows Update. -
Check for typos in paths:
If a command fails (e.g.,
cd My Documents), verify the exact folder name withlsordir. -
Reinstall software (last resort):
If a critical tool (like Python) breaks, uninstall it via:
- macOS: Use
brew uninstall python(if installed via Homebrew) or delete the app from Applications. - Windows: Use Add or Remove Programs in Settings.
- Linux: Use your package manager (e.g.,
sudo apt remove python3on Debian-based systems).
- macOS: Use
Frequently Asked Questions
How do I exit a frozen terminal?
Press Ctrl + C to interrupt. If that fails, close the terminal window (Windows) or force-quit it (macOS/Linux) by pressing Cmd + Option + Esc (macOS) or Alt + F2 (Linux) and selecting "Quit".
Can I use the terminal to delete files permanently?
Yes, but be careful. In macOS/Linux, rm -rf /path/to/file deletes files without confirmation. On Windows, del /q /f file.txt forces deletion. Never use rm -rf on a drive like /—it will erase your entire system.
How do I find my IP address using the terminal?
Use these commands based on your OS:
- macOS/Linux:
ifconfig | grep "inet "(look for lines starting with 192. or 10.) - Windows:
ipconfig(look for "IPv4 Address").
Why does my terminal say "command not found"?
This means the command isn’t installed or isn’t in your system’s default path. Try:
- Installing the missing tool (e.g.,
sudo apt install giton Debian-based Linux). - Adding the tool’s directory to your path (elixir:
export PATH="$PATH:/usr/local/opt/elixir/bin"). - Using the full path to the command (e.g.,
/usr/bin/python3).
How do I clear the terminal screen?
Press Ctrl + L (works on most terminals). Alternatively, use:
- Linux/macOS:
clear - Windows:
cls
Is the terminal safe for beginners?
Yes! Start with simple commands and avoid risky actions like editing system files. Always double-check paths before running deletion commands. If unsure, practice in a test directory (e.g., create a folder named `test` and experiment there).
The terminal is a powerful tool—mastering it saves time and gives you deeper control over your computer.