Linux Cheatsheet
Finding and Searching
Use this Linux reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
find — Locate Files
find . -name "*.log" # by filename (case-sensitive) find . -iname "*.LOG" # case-insensitive find /etc -type f # regular files only find /etc -type d # directories only find . -type l # symlinks only find . -empty # empty files and dirs find . -size +10M # larger than 10 MB find . -size -1k # smaller than 1 KB find . -size 100c # exactly 100 bytes find . -mtime -7 # modified in last 7 days find . -mtime +30 # modified more than 30 days ago find . -newer ref.txt # newer than ref.txt find . -user alice # owned by alice find . -group staff # owned by group staff find . -perm 644 # exact permissions find . -perm /u+x # any executable by owner find . -maxdepth 2 # limit search depth find . -mindepth 1 -maxdepth 1 # immediate children only
find + Actions
find . -name "*.tmp" -delete # delete matches find . -name "*.sh" -exec chmod +x {} \; # exec per file find . -name "*.log" -exec grep -l "error" {} \; find . -name "*.bak" -exec rm {} + # exec batched (faster) find . -name "*.txt" | xargs wc -l # pipe to xargs find . -name "*.txt" -print0 | xargs -0 grep "TODO" # handle spaces in names
Combining Conditions
find . -name "*.js" -not -path "*/node_modules/*" find . \( -name "*.log" -o -name "*.tmp" \) -mtime +7 find . -name "*.conf" -and -user root
locate — Fast Name Search
locate nginx.conf # search indexed database locate -i readme # case-insensitive locate -c "*.log" # count matches sudo updatedb # rebuild index (or runs nightly via cron)
locatesearches a pre-built database — very fast but may be stale. Usefindfor real-time results.
which / whereis / type
which python3 # path of first match in $PATH which -a python3 # all matches in $PATH whereis python3 # binary + man + source paths type -a ls # alias, function, or binary? command -v python3 # POSIX-safe which (exit 0/1)
grep — Search File Contents
grep -r "secret" /etc/ # recursive grep -rn "TODO" ./src/ # with line numbers grep -rl "error" ./logs/ # filenames only grep -ri "password" /etc/ # case-insensitive recursive grep --include="*.py" -r "import" . # filter by filename pattern grep --exclude-dir=".git" -r "fix" . # exclude directories
ripgrep (rg) — Faster grep
rg "error" ./logs/ # search recursively (respects .gitignore) rg -i "warning" . # case-insensitive rg -n "def " app.py # line numbers rg -l "TODO" . # filenames only rg -t py "import" . # filter by file type rg -g "*.md" "section" . # glob filter rg "error" -A 2 -B 1 # context lines rg --no-ignore "secret" . # ignore .gitignore
fd — Faster find
fd "\.log$" # regex on filename fd -t f "config" # files only fd -e log # by extension fd -H "^\.env" # include hidden files fd --exclude node_modules "*.js" fd -x rm {} # execute per result
Searching by Content — Specialized Tools
# Search compressed files zgrep "error" access.log.gz zcat file.gz | grep "pattern" # Binary files strings binary | grep "VERSION" hexdump -C file | head # Search man pages man -k "copy file" # apropos keyword mandb # rebuild man database