Git & Terminal Cheatsheet

Navigating and Files

Use this Git & Terminal reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Moving Around

cd projects         # enter the projects directory
cd ~                # go home (plain cd also goes home)
cd ..               # up one level
cd ../..            # up two levels
cd -                # jump back to the previous directory
pushd ~/work        # cd AND remember where you were
popd                # return to the remembered directory

Creating

mkdir app               # make a directory
mkdir -p src/api/v1     # make nested directories in one shot
touch README.md         # create an empty file (or update its timestamp)
touch a.txt b.txt       # several at once

Copying and Moving

cp notes.txt backup.txt         # copy a file
cp notes.txt ~/docs/            # copy into a directory
cp -r src src-backup            # copy a directory recursively
cp -p config.yml config.bak     # preserve permissions and timestamps
mv old.txt new.txt              # RENAME a file
mv app.log logs/                # MOVE a file into a directory
mv src/*.test.js tests/         # move by glob
mv -i a.txt b.txt               # prompt before overwriting

mv is both rename and move, the difference is only whether the target is a new name or an existing directory.

Deleting

rm file.txt             # delete a file
rm -i *.log             # confirm each deletion
rmdir empty-dir         # delete an EMPTY directory only
rm -r old-project       # delete a directory and everything in it
rm -rf node_modules     # same, without prompting on write-protected files

rm is permanent, there is no recycle bin. Double-check the path, and be especially careful with rm -rf plus variables or globs.

Finding Files (find)

find . -name "*.ts"                 # by name pattern, recursively
find . -iname "readme*"             # case-insensitive
find . -type d -name node_modules   # directories only (f = files)
find . -type f -size +10M           # files larger than 10 MB
find . -mtime -1                    # modified in the last 24 hours
find . -name "*.pyc" -delete        # find and delete
find . -name "*.sh" -exec chmod +x {} \;   # run a command on each match
find . -path ./node_modules -prune -o -name "*.js" -print  # skip a directory

Searching File Contents (grep)

grep "TODO" app.js              # lines containing TODO
grep -r "apiKey" src/           # recursive through a directory
grep -rn "apiKey" src/          # ...with file names and line numbers
grep -ri "error" logs/          # case-insensitive
grep -rl "useState" src/        # only list matching FILE names
grep -rn --include="*.ts" "fetch(" .   # limit to a file pattern
grep -E "user_[0-9]+" data.csv  # extended regex
grep -v "^#" config.ini         # invert: lines NOT matching
grep -C 3 "panic" app.log       # show 3 lines of context around matches

rg (ripgrep) is a much faster drop-in for recursive grep and skips .gitignored files by default: rg "apiKey" src/.

Disk Usage

du -sh .                # total size of the current directory
du -sh */ | sort -h     # size of each subdirectory, sorted
df -h                   # free space per mounted filesystem

Quick Reference

CommandDoes
cp -r <src> <dst>copy file or directory
mv <src> <dst>move or rename
touch <file>create empty file
mkdir -p <path>create nested directories
rm -r <dir>delete directory recursively
find . -name "<glob>"find files by name
grep -rn "<text>" <dir>search file contents
du -sh <dir>directory size
ln -s <target> <link>create a symbolic link