The command line interface (CLI) lets you interact with your computer using text-based commands instead of a graphical interface. It gives you precise control over system operations, automates repetitive tasks, and is essential for development, server management, and advanced troubleshooting. No special hardware is required—just a standard computer and access to a terminal application.
What You'll Need
- A computer running Windows, macOS, or Linux
- Access to a terminal application (built-in on all modern systems)
- Basic familiarity with file paths and directory structures (helpful but not required)
Step-by-Step
- Open the terminal application:
- On Windows: Press
Win + R, typecmdorpowershell, and press Enter. For the newer Windows Terminal, search for "Windows Terminal" in the Start menu. - On macOS: Open Finder, go to Applications > Utilities, and double-click Terminal. Alternatively, use Spotlight Search (
Cmd + Space), type "Terminal", and press Enter. - On Linux (e.g., Ubuntu): Press
Ctrl + Alt + T, or open the Applications menu and search for "Terminal".
- On Windows: Press
- Verify you're in the correct shell: Most systems use
bashorzshby default. Typeecho $SHELLand press Enter. You should see a path like/bin/bashor/bin/zsh. If you see an error, your shell may differ—but basic commands still work. - Check your current location: Type
pwd(print working directory) and press Enter. This shows your absolute path (e.g.,/Users/yournameon macOS/Linux orC:\Users\yournameon Windows). - View available commands: Type
ls(macOS/Linux) ordir(Windows) and press Enter. This lists files and folders in your current directory. - Navigate directories:
- To move into a subdirectory:
cd foldername(e.g.,cd Documents) - To move up one level:
cd .. - To go to your home directory:
cd(no arguments) - On Windows, use backslashes for paths with spaces:
cd "C:\Program Files"
- To move into a subdirectory:
- Create a new file: Type
touch filename.txt(macOS/Linux) orNew-Item -ItemType file -Path filename.txt(PowerShell) and press Enter. This creates an empty file in your current directory. - Write to a file using a text editor:
- Open
nano(simplest beginner-friendly editor):nano filename.txt - Type your content, then press
Ctrl + Oto save,Enterto confirm, andCtrl + Xto exit. - On Windows, use
notepad filename.txtto open Notepad directly from the terminal.
- Open
- Run a command with arguments: For example,
ping google.comtests network connectivity. You can add flags likeping -c 4 google.com(macOS/Linux) to send only 4 packets. - Check command history: Type
history(macOS/Linux) orGet-History(PowerShell) to list recent commands. Press↑or↓to cycle through previous commands. - Learn about any command: Type
man commandname(macOS/Linux) for the manual page, orGet-Help commandname(PowerShell). Pressqto quit the manual viewer.
Common Mistakes
- Case sensitivity: On macOS and Linux,
File.txtandfile.txtare different files. Typingls Documentswhen the folder is nameddocumentswill fail. - Missing spaces: Commands like
cd..(no space) are invalid. Always usecd ... - Incorrect path separators: Windows uses backslashes (
\), while macOS/Linux use forward slashes (/). Mixing them (C:/Usersin CMD) causes errors. - Running commands without permission: System edits (e.g.,
rm /etc/config) require elevated privileges. Usesudoon macOS/Linux (with caution) or run PowerShell as Administrator on Windows. - Assuming Windows commands work elsewhere:
dirdoesn’t work in bash on macOS/Linux—uselsinstead. PowerShell is cross-platform but still uses different syntax.
Tips
- Use Tab completion: Type
cd Docthen pressTab—the shell auto-completes toDocumentsif it’s the only match. PressTabtwice to see all options. - Copy/paste safely: Right-click in the terminal and choose "Paste" (or
Ctrl + Shift + Vin many terminals). AvoidCtrl + Vin bash—it may trigger a special character instead of pasting. - Start simple: Practice
ls,cd, andpwddaily for a week. They’re the foundation for everything else. - Use parentheses for grouping in Windows: PowerShell commands like
Get-Process | Where-Object { $_.CPU -gt 100 }rely on curly braces and dollar signs for variables. - Create aliases: In
~/.bashrc(Linux/macOS) or your PowerShell profile, addalias ll='ls -la'to shorten long commands.
Troubleshooting
If your command returns an error, follow these steps in order:
- Check for typos: Re-type the command manually—copy/paste can introduce invisible characters. Compare it to official documentation.
- Verify the command exists: Type
which commandname(macOS/Linux) orGet-Command commandname(PowerShell). If nothing returns, the command isn’t installed or in your$PATH. - Check directory context: Run
pwdorcdto confirm you’re in the expected location. A missing file in~/Downloadsmay actually be in~. - Review permissions: If you see "Permission denied", try adding
sudo(macOS/Linux) or running the terminal as Administrator (Windows). Warning:sudo rm -rf /deletes your entire system—never run destructive commands blindly. - Restart your terminal: Close and reopen the window. Sometimes environment variables or path settings get corrupted in long sessions.
- Update your shell: Outdated shells cause compatibility issues. On macOS, run
brew upgrade bash(if using Homebrew). On Windows, ensure Windows Terminal is updated via the Microsoft Store.
Frequently Asked Questions
Is the command line faster than using a mouse?
Yes—for repetitive tasks like renaming 100 files, searching logs, or deploying code. Typing for f in *.log; do gzip "$f"; done compresses all log files instantly, while doing it manually would take minutes.
Can I use the command line on a Chromebook?
Yes—if you enable Linux (Beta) in Settings > Developers > Turn on Linux tools. After setup, open the Terminal app from the launcher and use standard Linux commands.
Do I need to memorize hundreds of commands?
No. Focus on the top 10: ls, cd, pwd, mkdir, touch, cat, grep, man, history, and clear. Most tools include help flags like --help to list options on demand.
Why does my Windows command prompt show C:\> with no folder name?
That means your current directory is your user profile root (e.g., C:\Users\YourName). Type cd alone to confirm, or cd Desktop to move to your Desktop folder.
Can I run graphical apps from the command line?
Yes—on macOS, use open -a Safari to launch apps. On Linux, firefox opens the browser. On Windows, start chrome launches Chrome. These commands start GUI applications but don’t replace the mouse for interaction.
Is the command line safe for beginners?
Yes—with caution. Avoid commands like rm (delete) or format until you understand their risks. Start with read-only commands like ls and cat to explore safely. Always double-check your path before deleting or modifying files.