These commands form the foundation of terminal literacy. About ten commands cover the vast majority of terminal interactions, including the operations tools like Claude Code perform when exploring a codebase, running tests, or modifying files.
Navigation: Finding Your Way Around
pwd prints your current location. Run it first to orient yourself whenever you’re unsure where you are.
$ pwd/home/username/projectsls lists what’s in the current directory. The -la flags show hidden files (those starting with .) in detailed format:
$ ls -latotal 24drwxr-xr-x 3 user user 4096 Jan 15 10:30 .drwxr-xr-x 18 user user 4096 Jan 14 09:00 ..-rw-r--r-- 1 user user 220 Jan 15 10:30 .gitignoredrwxr-xr-x 2 user user 4096 Jan 15 10:30 src-rw-r--r-- 1 user user 1024 Jan 15 10:30 package.jsonThe detailed output shows permissions, owner, size, last modified date, and name. The d at the beginning of a line means it’s a directory. Hidden files (starting with .) include configuration files like .gitignore that are invisible to a plain ls.
cd changes your location. Use cd .. to go up one level, cd ~ to jump home, and cd - to toggle back to your previous location:
cd Documents # Enter Documents foldercd ../.. # Go up two levelscd ~/projects/myapp # Jump to absolute path using home shortcutcd - # Return to wherever you were beforeThe cd - shortcut is underappreciated. When you’re bouncing between two directories — say, a model file and its test file — cd - takes you back without typing the path again.
File Operations: Creating and Managing Files
mkdir creates directories. Use -p to create nested folders in one command:
mkdir projectsmkdir -p projects/web/frontend/componentsWithout -p, mkdir fails if any parent directory doesn’t exist. With -p, it creates the entire chain. Always use -p when creating nested structures.
touch creates empty files or updates timestamps on existing ones:
touch newfile.txttouch index.js styles.css # Create multiple filestouch is harmless on existing files — it just updates the “last modified” timestamp without changing content. It’s the standard way to create a new empty file from the command line.
cp copies files. Add -r for directories (recursive copy):
cp original.txt backup.txtcp -r src/ src-backup/mv moves or renames files. There’s no separate rename command in Unix — moving a file to a new name in the same directory is how you rename:
mv oldname.txt newname.txt # Renamemv file.txt ~/Documents/ # Move to DocumentsBe aware that mv overwrites the destination without warning if a file already exists there.
rm removes files permanently. See Terminal Safety for Beginners for the full safety discussion. The basics:
rm unwanted.txt # Delete file (no confirmation!)rm -i important.txt # Ask before deletingrm -r foldername/ # Delete folder and contentsViewing File Contents
cat displays an entire file at once. Best for short files — configuration files, small scripts, YAML:
cat config.jsonFor anything longer than a screenful, cat dumps everything at once and you lose the beginning. Use less instead.
less provides paginated viewing for longer files. Navigate with arrow keys, space for next page, q to quit:
less longfile.logInside less, you can search with /pattern (forward search) or ?pattern (backward search). Press n to jump to the next match. This is invaluable for navigating large log files or long source files.
head and tail show the first or last lines. The -n flag specifies how many:
head -n 20 file.txt # First 20 linestail -n 50 server.log # Last 50 linestail -f app.log # Follow file in real-time (great for logs)tail -f is particularly useful during development. It watches a file and prints new lines as they’re added — perfect for monitoring log files while a process runs. Press Ctrl+C to stop following.
Finding Things
grep searches for text patterns inside files. This is one of the most powerful and frequently used commands — Claude Code relies heavily on its faster cousin, ripgrep (rg), for the same purpose.
grep "error" logfile.txt # Find lines containing "error"grep -i "warning" app.log # Case-insensitive searchgrep -r "TODO" ./src/ # Search recursively in src foldergrep -n "function" script.js # Show line numbersThe flags you’ll use most:
-i: case-insensitive (finds “Error”, “ERROR”, “error”)-r: recursive (searches all files in all subdirectories)-n: show line numbers alongside matches-c: count matches instead of showing them
Combining flags is common: grep -rni "error" ./src/ searches recursively, case-insensitively, with line numbers — one of the most useful commands you can run.
find locates files by name or attributes. Where grep searches inside files, find searches for files themselves:
find . -name "*.txt" # Find all .txt files from current directoryfind /home -name "config" # Find files named "config"find . -type f -name "*.log" # Find only files (not directories)The . in find . means “start searching from the current directory.” You can replace it with any path.
which reveals where a command lives on your system:
which python # Shows /usr/bin/python or similarwhich nodeThis is useful when you have multiple versions of a tool installed and want to know which one the terminal is using. If which returns nothing, the command isn’t installed or isn’t in your PATH.
Combining Commands
Unix commands are designed to work together. The pipe operator | sends the output of one command as input to the next:
ls -la | grep ".json" # List files, filter to JSON filescat logfile.txt | grep "error" # Read file, filter to error linesgrep -r "TODO" ./src/ | wc -l # Count TODO comments in source codeThe redirect operators write output to files:
ls > filelist.txt # Write file list to filelist.txtecho "hello" >> notes.txt # Append "hello" to notes.txt> creates or overwrites the file. >> appends to it. This distinction matters — using > on an existing file replaces its contents entirely.
Quick Reference
| Command | Purpose | Safe? |
|---|---|---|
pwd | Show current directory | Yes |
ls | List directory contents | Yes |
cd | Change directory | Yes |
cat | Display file contents | Yes |
less | Paginated file viewing | Yes |
head/tail | First/last lines of file | Yes |
grep | Search text in files | Yes |
find | Locate files by name | Yes |
which | Find command location | Yes |
mkdir | Create directories | Yes |
touch | Create empty files | Yes |
cp | Copy files | Mostly |
mv | Move/rename files | Caution |
rm | Delete files | Caution |
The first ten commands in this table are read-only. They’re where you’ll spend 90% of your time, and they can’t damage anything. The last three modify your filesystem and deserve the attention described in Terminal Safety for Beginners.