TL;DR: You do not need to memorize hundreds of commands. You need about 30 that cover navigation, file management, process control, npm/package management, and git. This guide groups them by what they do so you can find what you need when AI generates a command you do not recognize.

pwd              # Print working directory — shows your current location
ls               # List files in current directory
ls -la           # List all files including hidden (.dotfiles) with details
cd myproject     # Change into the 'myproject' directory
cd ..            # Go up one directory level
cd ~             # Go to your home directory
cd -             # Go back to the previous directory

The most important habit: always know where you are before running commands. pwd tells you. Running npm install in the wrong directory is a common source of confusion.

Files and Directories

mkdir my-project         # Create a directory
mkdir -p a/b/c           # Create nested directories (no error if exists)
touch filename.txt       # Create an empty file
cp source.txt dest.txt   # Copy a file
cp -r source/ dest/      # Copy a directory and all its contents
mv old.txt new.txt       # Move or rename a file
rm filename.txt          # Delete a file (no trash — gone immediately)
rm -rf directory/        # Delete a directory and all contents (CAREFUL)
cat file.txt             # Print file contents to terminal
head -20 file.txt        # Show first 20 lines of a file
tail -f app.log          # Stream a log file in real time (follow)
grep "error" app.log     # Search for "error" in a file

⚠️ rm -rf Warning

rm -rf permanently deletes files and directories with no confirmation and no undo. Never run rm -rf / or rm -rf ./ (note the space before slash). Always double-check the path before running rm -rf.

npm and Package Management

npm install                     # Install all dependencies from package.json
npm install express             # Install a package and add to dependencies
npm install --save-dev eslint   # Install as dev dependency
npm install -g nodemon          # Install globally (available system-wide)
npm uninstall express           # Remove a package
npm run dev                     # Run the 'dev' script from package.json
npm run build                   # Run the 'build' script
npm run lint                    # Run the 'lint' script
npm list                        # List installed packages
npm outdated                    # Show packages with newer versions available
npm update                      # Update all packages to latest minor versions
npx create-next-app my-app      # Run a package without installing globally

npx is particularly important — it runs a package directly from the npm registry without a global install. AI tools use npx for one-time setup commands like npx prisma migrate dev or npx eslint --init.

Process Control

Ctrl+C                  # Stop the currently running process (dev server, etc.)
Ctrl+Z                  # Suspend a process (send to background)
Ctrl+D                  # Exit the current shell session

ps aux                  # List all running processes
ps aux | grep node      # Filter processes containing "node"
kill 12345              # Kill process with ID 12345 (graceful)
kill -9 12345           # Force kill a process (immediate, no cleanup)
lsof -i :3000           # Show what is using port 3000
lsof -ti :3000 | xargs kill -9  # Kill whatever is running on port 3000

The lsof -ti :3000 | xargs kill -9 command is invaluable when your dev server crashes and leaves the port occupied. "Address already in use" errors are solved with this pattern.

Environment and Variables

echo $HOME              # Print an environment variable value
echo $NODE_ENV          # Check the current environment
export PORT=4000        # Set an environment variable for this session
env                     # List all current environment variables
env | grep PORT         # Find specific environment variables

# Running with environment variables inline
NODE_ENV=production node server.js
DATABASE_URL=postgres://... npm run migrate

Git Quick Reference

git status              # See changed files
git add .               # Stage all changes
git commit -m "message" # Commit staged changes
git push                # Push to remote
git pull                # Pull latest changes
git log --oneline       # Compact commit history
git diff                # See unstaged changes
git stash               # Temporarily save uncommitted changes
git stash pop           # Restore stashed changes
git checkout -b feature # Create and switch to a new branch

Searching

# Find files by name
find . -name "*.json" -not -path "*/node_modules/*"

# Search inside files
grep -rn "TODO" --include="*.ts" .
grep -rn "dangerouslySetInnerHTML" --include="*.tsx" .

# Search with context lines
grep -rn -A 2 -B 2 "api_key" .  # Show 2 lines before/after each match

The grep search pattern is critical for security audits — search for dangerouslySetInnerHTML, eval(, or innerHTML = to find potential XSS vulnerabilities in AI-generated code.

Reading Output and Pipes

# | (pipe) sends output of one command to another
ls -la | grep ".json"       # Filter ls output to .json files
cat package.json | grep name # Find name in package.json

# > redirects output to a file
npm run build > build.log 2>&1  # Save build output to file (including errors)

# && runs second command only if first succeeds
npm install && npm run build

# || runs second command only if first fails
npm test || echo "Tests failed"

Terminal Shortcuts

  • Tab — Autocomplete file names and commands
  • ↑ / ↓ — Navigate command history
  • Ctrl+R — Search command history
  • Ctrl+L — Clear the terminal screen (keeps history)
  • Ctrl+A — Jump to beginning of line
  • Ctrl+E — Jump to end of line
  • Ctrl+W — Delete the word before cursor

What to Learn Next

Next Step

Open your terminal right now and practice: pwdls -lacd into your project → ls -la again. Notice the .git folder (hidden unless you use -a). That exploration builds the spatial intuition for the command line that AI developers use constantly.

FAQ

Use Windows Subsystem for Linux (WSL2) with Ubuntu for the best compatibility with the bash/zsh commands in this guide. Alternatively, Git Bash (installed with Git for Windows) provides most Unix commands. Windows Terminal is a good terminal emulator for either.

Both are Unix shells — the programs that interpret your commands. macOS uses zsh by default (since Catalina); Linux typically uses bash. For most purposes they behave identically. The commands in this guide work in both.

Press Ctrl+C in the terminal where the server is running. This sends an interrupt signal and gracefully shuts down most Node.js processes. If that does not work, use lsof -ti :3000 | xargs kill -9 (replace 3000 with your port).

sudo (Super User DO) runs a command with administrator privileges. Required for installing system-level software. For development, you should rarely need sudo — if npm or other tools require it for basic operations, that is usually a sign of a permissions problem with your installation.

Use && to run commands sequentially (each only runs if the previous succeeded): npm install && npm run dev. Use ; to run commands regardless of success: npm run lint; npm run test. Use & to run in the background: npm run server &.