ServicesAboutNotesContact Get in touch →
EN FR
Note

Essential Terminal Commands

The core terminal commands for navigation, file operations, viewing content, and finding things — the foundation of terminal literacy

Planted
claude codeai

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.

pwd prints your current location. Run it first to orient yourself whenever you’re unsure where you are.

Terminal window
$ pwd
/home/username/projects

ls lists what’s in the current directory. The -la flags show hidden files (those starting with .) in detailed format:

Terminal window
$ ls -la
total 24
drwxr-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 .gitignore
drwxr-xr-x 2 user user 4096 Jan 15 10:30 src
-rw-r--r-- 1 user user 1024 Jan 15 10:30 package.json

The 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:

Terminal window
cd Documents # Enter Documents folder
cd ../.. # Go up two levels
cd ~/projects/myapp # Jump to absolute path using home shortcut
cd - # Return to wherever you were before

The 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:

Terminal window
mkdir projects
mkdir -p projects/web/frontend/components

Without -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:

Terminal window
touch newfile.txt
touch index.js styles.css # Create multiple files

touch 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):

Terminal window
cp original.txt backup.txt
cp -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:

Terminal window
mv oldname.txt newname.txt # Rename
mv file.txt ~/Documents/ # Move to Documents

Be 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:

Terminal window
rm unwanted.txt # Delete file (no confirmation!)
rm -i important.txt # Ask before deleting
rm -r foldername/ # Delete folder and contents

Viewing File Contents

cat displays an entire file at once. Best for short files — configuration files, small scripts, YAML:

Terminal window
cat config.json

For 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:

Terminal window
less longfile.log

Inside 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:

Terminal window
head -n 20 file.txt # First 20 lines
tail -n 50 server.log # Last 50 lines
tail -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.

Terminal window
grep "error" logfile.txt # Find lines containing "error"
grep -i "warning" app.log # Case-insensitive search
grep -r "TODO" ./src/ # Search recursively in src folder
grep -n "function" script.js # Show line numbers

The 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:

Terminal window
find . -name "*.txt" # Find all .txt files from current directory
find /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:

Terminal window
which python # Shows /usr/bin/python or similar
which node

This 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:

Terminal window
ls -la | grep ".json" # List files, filter to JSON files
cat logfile.txt | grep "error" # Read file, filter to error lines
grep -r "TODO" ./src/ | wc -l # Count TODO comments in source code

The redirect operators write output to files:

Terminal window
ls > filelist.txt # Write file list to filelist.txt
echo "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

CommandPurposeSafe?
pwdShow current directoryYes
lsList directory contentsYes
cdChange directoryYes
catDisplay file contentsYes
lessPaginated file viewingYes
head/tailFirst/last lines of fileYes
grepSearch text in filesYes
findLocate files by nameYes
whichFind command locationYes
mkdirCreate directoriesYes
touchCreate empty filesYes
cpCopy filesMostly
mvMove/rename filesCaution
rmDelete filesCaution

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.