Searching and finding¶
Warning
This page is under construction!
Questions to think about:¶
How can we find files? How can we find things in files?
Commands of the Day¶
grepis a contraction of global/regular expression/print. It finds and prints lines in files that match a pattern.regular expressions are patterns that can include wildcards
Usage:
grep pattern filenamegrep -wlimits to word boundariesgrep -nprints the line numbers that matchgrep -imakes search case-insensitivegrep -vinverts the search to output that does not contain the patterngrep -Enotes that the pattern is an extended regular expression that can contain wildcards
findcommand finds files!-typed or f for directories or files-namematches a name, but look out for order of execution! Filenames with wildcards need quotes. For example,find . -name "*.txt"
$()to combine commands. Code inside this runs first!For example,
wc -l $(find . -name "*.txt")
Resources¶
This lesson is adapted from The Unix Shell on Software Carpentry.