Just Enough CLI · Step 5 Free
Finding things: wildcards, grep, find
Half of data work is finding the right file or the right line in a log. These are the tools.
Wildcards (globs)
The shell expands patterns into matching filenames before the command runs:
at*— all names that start withat*at— all names that end withat*at*— all names that containat?— exactly one character
ls *.csv # every CSV in this directory
rm tmp_* # careful — everything starting with tmp_
(Windows people: where CMD used *.*, Linux just uses *.)
grep — search inside files
grep prints the lines that match an expression. You will use it every single day:
grep error app.log # lines containing "error"
grep -i error app.log # case-insensitive
grep -v DEBUG app.log # invert: lines that do NOT match
grep root /etc/passwd # the classic example
grep understands regular expressions — the same idea you met in the SQL and PySpark courses:
.matches exactly one character.*matches any number of characters.+matches one or more characters
Standard input, output, and pipes
Unix processes read from an input stream (stdin) and write to an output stream (stdout, plus stderr for errors). The pipe | connects one command’s output to the next command’s input:
cat app.log | grep error | head # first 10 error lines
history | grep ssh # find that ssh command you ran last week
This chaining is the whole Unix philosophy: small tools, combined.
find and locate
When you know a file exists but not where:
find ~/projects -name "*.sql" -print # search a directory tree, live
locate settings.yml # search a prebuilt index — much faster
locate uses an index the system rebuilds periodically, so very new files may not appear in it yet.
Practice in your terminal:
- Run
ls *.md(or*.txt) in some project directory. - Pick any text file and grep it:
grep -i the file.txt. - Chain a pipe:
history | grep cd— see your own navigation habits. - Find every Markdown file under your home:
find ~ -name "*.md" | head.