Command Line Basics
Learn the terminal, essential commands, and how to navigate and manipulate the file system.
What you'll learn
- What the terminal (shell) is and how to open it
- Essential commands: ls, cd, pwd, mkdir, rm, cp, mv
- How to read and search file contents with cat, grep, less
- Pipes and redirection to combine commands
Concept
The Terminal
The command line, also called the terminal or shell, is a text-based interface for interacting with your computer's operating system. Instead of clicking buttons and menus, you type commands and press Enter. Every developer and DevOps engineer needs command-line fluency because servers, build tools, and automation scripts all run in the shell.
On macOS the default shell is zsh; on most Linux distributions it is bash; on Windows you can use PowerShell or install Git Bash and the Windows Subsystem for Linux (WSL). The concepts are the same across all of them, though some commands differ slightly.
Essential Navigation Commands
The most fundamental commands let you move around the file system and see what is there. pwd prints your current directory. ls lists files in the current directory. cd changes the directory. These three commands are the starting point for everything else you will do on the command line.
File Operations
You can create, copy, move, and delete files and directories entirely from the terminal. mkdir creates directories. touch creates an empty file. cp copies files, mv moves or renames them, and rm removes them. The -r flag makes rm and cp work recursively on directories. Always be careful with rm -rf — it deletes without asking for confirmation.
Pipes and Redirection
One of the most powerful features of the shell is the ability to chain commands together. The pipe operator | sends the output of one command as input to another. Redirection operators > and >> send output to a file. For example, ls | grep ".txt" lists only text files, and echo "hello" > file.txt writes text to a file. These building blocks let you compose complex operations from simple commands.
Learning the Shell
The best way to learn the command line is to use it daily. Start by replacing file explorer clicks with terminal commands. Learn one new command each day. Use man command or command --help to read built-in documentation. Bookmark a cheat sheet. Over time, you will build muscle memory and the terminal will become faster than any GUI. Every DevOps tool — Docker, Kubernetes, Terraform — is a command-line tool, so this foundation is essential for everything that follows.
Example
# Navigate the file system
pwd # print current directory
ls -la # list all files with details
cd ~/projects # change to projects directory
# Create and manipulate files
mkdir -p myapp/src # create nested directories
touch myapp/src/index.js # create an empty file
cp index.js index.bak.js # copy a file
mv index.bak.js backup/ # move a file
# Search and filter
grep -r "TODO" . # search for TODO in all files
cat package.json | head -20 # show first 20 lines
These commands cover the essentials: navigation, file manipulation, and searching. Practice them until they are muscle memory — you will use them every day as a DevOps engineer.
Try it
- Regex Tester
Test regular expressions for grep and sed patterns.
- Cron Parser
Parse cron schedule expressions from the command line.
- Crontab Generator
Generate cron job schedules visually.
Common mistakes
The mistake
Using rm -rf without checking the path
The fix
Always verify your current directory with pwd and use ls to confirm what you are about to delete. A typo like rm -rf / can destroy your entire system.
The mistake
Forgetting that Linux paths use forward slashes
The fix
On Linux and macOS, paths use forward slashes (/). On Windows PowerShell, both work, but in Git Bash always use forward slashes.
Practice Command Line Basics
6 exercises
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.