Skip to main content
Early access — new tools and guides added regularly
🟢 Zero to Claude Code — Guide 7 of 9
View track
>_ claude codeBeginner25 min

Understanding the Terminal: Commands Every AI User Needs

A comprehensive guide to the terminal commands that power AI-assisted development. Go beyond the basics with pipes, redirects, environment variables, and process management.

What you will build
Fluency in 20+ terminal commands and the confidence to troubleshoot any CLI workflow

Why terminal fluency unlocks AI power

Claude Code operates entirely in your terminal. The more comfortable you are with the command line, the more effectively you can direct Claude Code, understand what it is doing, and debug when things go wrong. This guide goes deeper than the basics — we cover the commands and concepts that separate casual terminal users from confident ones. You will learn how to inspect and manipulate files, chain commands together, manage environment variables, and control processes. These are not obscure skills reserved for system administrators. They are everyday tools that make you faster and more capable with Claude Code. When Claude Code suggests running a command, you will understand what it does. When something fails, you will know how to investigate. When you need to set up a new project or server, you will not need to search for every step. Think of the terminal as the cockpit of your development environment. The graphical interfaces you are used to — file managers, text editors, settings panels — are simplified views of what the terminal can do. The terminal gives you the full picture and the full control. Every professional developer lives in the terminal. After this guide, you will understand why. Open your terminal now and follow along. Every command in this guide is meant to be typed and run. Reading about terminal commands without running them is like reading about swimming without getting in the water.

File inspection: cat, less, head, tail, and wc

You already know ls lists files. Now learn to look inside them. The command `cat package.json` prints an entire file to your terminal. For short files this is perfect. For long files, the output scrolls past too fast. That is where less comes in: `less README.md` opens the file in a scrollable viewer. Press space to page down, b to page back, q to quit, and / to search within the file. When you only need the beginning or end of a file, use head and tail: `head -20 server.log` shows the first 20 lines, `tail -20 server.log` shows the last 20. The tail command has a powerful flag: `tail -f server.log` follows the file in real time, showing new lines as they are added. This is invaluable for watching log files while your application runs. The wc (word count) command measures files: `wc -l src/index.ts` counts lines, `wc -w README.md` counts words, `wc -c data.json` counts bytes. Combine these to quickly understand a codebase: `wc -l src/**/*.ts` counts lines in all TypeScript files. You should see output like: 42 src/index.ts, 108 src/utils.ts, 150 total. These inspection commands are essential when working with Claude Code because they let you verify changes. After Claude Code edits a file, run `head -30 src/index.ts` to check the first 30 lines without opening an editor. Quick verification keeps you in the terminal flow instead of context-switching to a GUI editor.

Finding things: find, grep, and which

Three commands that answer the question where is it? The find command searches for files by name, type, size, or modification date. `find . -name '*.ts'` finds all TypeScript files in the current directory and subdirectories. `find . -name '*.log' -mtime -1` finds log files modified in the last day. `find src -type d` lists all directories inside src. The grep command searches inside files for text patterns. `grep -r 'TODO' src/` searches all files in src for the word TODO. `grep -rn 'fetchUser' src/` does the same but includes line numbers with the -n flag. `grep -ri 'error' logs/` does a case-insensitive search with -i for error in logs. Combine find and grep for surgical precision: `find src -name '*.tsx' | xargs grep 'useState'` finds all TSX files that use the useState hook. The which command tells you where a program is installed: `which node` might output /usr/local/bin/node. This is essential for debugging command not found errors and understanding which version of a tool you are running. If `which python` returns nothing, Python is not on your PATH. If it returns /usr/bin/python instead of the version you installed, your PATH ordering is wrong. When Claude Code tells you to install a tool and it seems to not work, which is your first diagnostic command. These three commands — find, grep, which — are how experienced developers navigate codebases. Claude Code uses them internally too. Understanding them means you can follow Claude Code's reasoning when it searches your project.

Pipes and redirects: chaining commands together

Pipes are the terminal's superpower. The pipe operator | sends the output of one command as input to another. `ls -la | grep '.ts'` lists all files and filters to only show TypeScript files. `cat server.log | grep 'ERROR' | wc -l` counts how many error lines are in your log file. `history | grep 'npm'` shows all npm commands you have run recently. Each pipe creates a pipeline where data flows from left to right, each command transforming it. You can chain as many pipes as you need: `cat data.csv | sort | uniq | wc -l` counts the number of unique lines in a CSV file. Redirects send output to files instead of the terminal. The > operator writes output to a file, overwriting it: `echo 'Hello' > greeting.txt` creates a file containing Hello. The >> operator appends: `echo 'World' >> greeting.txt` adds World to the end of the file. The < operator sends a file as input: `sort < names.txt` sorts the lines in names.txt. Combine pipes and redirects for powerful one-liners: `grep -r 'console.log' src/ | sort > debug-statements.txt` finds all console.log statements and saves the sorted list to a file. You do not need to memorise complex pipelines. Claude Code will write them for you. But understanding the concept of pipes and redirects means you can read and modify what Claude Code produces. When Claude Code chains together five commands with pipes, you will know exactly what each step does and why it is there.

Environment variables: configuration without code

Environment variables are key-value pairs that configure your system and applications. They are how you tell programs where to find things, which mode to run in, and what credentials to use — without putting that information in your code. View all current environment variables with `env` or `printenv`. View a specific one with `echo $HOME` or `echo $PATH`. The PATH variable is the most important — it is a colon-separated list of directories where your terminal looks for programs. When you type node, the terminal searches each PATH directory until it finds the node executable. Set a temporary variable for the current session only: `export API_KEY=sk-abc123`. This variable is available to any program you run in this terminal session. When you close the terminal, it disappears. Set a permanent variable by adding the export line to your shell profile. On macOS with zsh: add `export API_KEY=sk-abc123` to ~/.zshrc. On Linux with bash: add it to ~/.bashrc. After editing the profile, run `source ~/.zshrc` or `source ~/.bashrc` to load it without restarting your terminal. For projects, use .env files instead of system-wide variables. Create a file called .env in your project root containing lines like `API_KEY=sk-abc123` and `DATABASE_URL=postgres://localhost/mydb`. Libraries like dotenv for Node.js or python-dotenv for Python read this file automatically. Critical rule: never commit .env files to Git. Add .env to your .gitignore immediately. Environment variables often contain API keys, database passwords, and other secrets. Claude Code knows this convention and will remind you, but make it a habit yourself. Run `echo '.env' >> .gitignore` in every new project.

Process management: running and stopping programs

When you run `npm run dev`, your terminal is occupied by that process. You cannot type other commands until you stop it with Ctrl+C. This is fine for one process, but real development often requires multiple — a frontend server, a backend server, a database, a file watcher. There are several ways to manage multiple processes. The simplest: open multiple terminal tabs or windows. Each tab runs one process. This is what most beginners do, and it works. A more efficient approach: background processes. Add & to the end of a command to run it in the background: `npm run dev &`. The terminal returns immediately and you can type other commands. The jobs command lists all background processes in the current terminal. `fg` brings the most recent background process to the foreground. `fg %2` brings job number 2 to the foreground. `kill %1` terminates job number 1. For finding and stopping any process: `ps aux | grep node` lists all running Node.js processes. Each line shows a process ID (PID). Kill a specific process with `kill 12345` replacing with the actual PID. If it does not stop, `kill -9 12345` forces it. The lsof command shows which processes are using which ports: `lsof -i :3000` shows what is running on port 3000. This is essential when you see port already in use errors. Find the PID from lsof output and kill it. Claude Code frequently starts development servers and background processes. Understanding process management means you can clean up after a session, debug port conflicts, and run complex development environments without confusion.

File permissions and ownership

Every file and directory on your system has permissions that control who can read, write, and execute it. Run `ls -la` and you will see something like: -rw-r--r-- 1 user staff 1024 Jan 1 12:00 file.txt. The first column is the permission string. It has four parts: the file type (- for file, d for directory), owner permissions (rw-), group permissions (r--), and everyone-else permissions (r--). Each permission slot is either r (read), w (write), x (execute), or - (none). So -rw-r--r-- means: the owner can read and write, the group can read, and everyone else can read. Nobody can execute it. The chmod command changes permissions. The simplest form uses numbers: `chmod 755 script.sh` sets rwxr-xr-x where the owner can do everything and others can read and execute. `chmod 644 config.json` sets rw-r--r-- where the owner reads and writes and others read only. `chmod +x deploy.sh` adds execute permission — this is the most common chmod you will run, making a script executable so you can run it with `./deploy.sh`. Why this matters for Claude Code: when Claude Code creates a script, you often need to make it executable before you can run it. If you see Permission denied when running a script, `chmod +x script-name.sh` is usually the fix. When Claude Code installs global packages and you see permission errors, it is because your user does not have write access to the installation directory. Understanding permissions tells you whether to use sudo, change directory ownership with chown, or use a version manager like nvm that installs to your home directory and avoids these issues entirely.

Putting it all together: a real diagnostic workflow

Let us combine everything into a real workflow. You have been asked to investigate why a web application is running slowly. Start by checking what is running: `lsof -i :3000` confirms the app is on port 3000. Check the log file: `tail -100 logs/app.log | grep -i 'slow\|timeout\|error'` shows the last 100 log lines filtered for problems. Count errors by type: `grep -i 'error' logs/app.log | sort | uniq -c | sort -rn | head -10` shows the top 10 most common errors. Check disk space: `df -h` shows available space on all drives. Check the project for large files: `find . -type f -size +10M` finds files over 10 megabytes. Check how many dependencies are installed: `ls node_modules | wc -l` counts packages. Look for recent changes: `git log --oneline -20` shows the last 20 commits. Compare with the previous version: `git diff HEAD~5 --stat` shows which files changed in the last 5 commits. Now you have a complete picture: server status, error patterns, system resources, large files, and recent changes — all from the terminal, all in under two minutes. This is the power of terminal fluency. Each command is simple. Chained together, they give you diagnostic capabilities that no GUI tool can match. When you ask Claude Code to investigate a problem, it runs similar commands. Understanding them means you can follow its reasoning, ask better follow-up questions, and verify its conclusions. Practice this workflow on your own projects. Familiarity with these commands turns debugging from a frustrating guessing game into a systematic investigation.

Related Lesson

Your Development Environment

This guide is hands-on and practical. The full curriculum covers the conceptual foundations in depth with structured lessons and quizzes.

Go to lesson