grep1-8 Exercise 2: rg -uu Against grep ======================================== (Run in the practice repository from the chapter. Make it first with the block at the top of the chapter, then change into the proj folder.) echo "-uu against grep -rnI, same lines?" diff <(grep -rnI --exclude-dir=.git TODO . | sed 's|^\./||' | sort) <(rg -uu -n -g '!.git' TODO | tr '\\' / | sort) && echo " identical" echo for level in "" -u -uu -uuu; do printf 'rg %-5s -l TODO: ' "$level"; rg $level -l TODO | wc -l; done echo echo "what -u adds (compare rg and rg -u):" diff <(rg -l TODO | tr '\\' / | sort) <(rg -u -l TODO | tr '\\' / | sort) | grep '^>' | sed 's/^> / /' echo "what -uu adds on top of -u:" diff <(rg -u -l TODO | tr '\\' / | sort) <(rg -uu -l TODO | tr '\\' / | sort) | grep '^>' | sed 's/^> / /' | cut -c1-60 Output: -uu against grep -rnI, same lines? identical rg -l TODO: 4 rg -u -l TODO: 6 rg -uu -l TODO: 9 rg -uuu -l TODO: 10 what -u adds (compare rg and rg -u): build/out.js debug.log what -uu adds on top of -u: .env .git/hooks/sendemail-validate.sample .hidden-notes WHY THIS WORKS AS AN ANSWER --------------------------- rg -uu switches off ignore files and the hidden-file rule but keeps skipping binary files, which is what grep -rI does; -g '!.git' leaves out the .git folder, which -uu would otherwise search (grep needed --exclude-dir=.git for the same reason). With paths normalised (backslash to slash, the leading ./ removed) and sorted, diff finds no difference. The counts per level show the three switches in order: -u (1) stops obeying .gitignore, so build/out.js and debug.log appear (and .env is hidden and still skipped); -uu (2) also searches hidden files and folders, which adds .env, .hidden-notes and .git's sample hooks; -uuu (3) also searches binary files, which adds data/logo.bin. The two difference listings show which files each switch brought in. The lesson for real work is the same as at the end of the chapter: when a search finds less than you expect, step through -u, -uu, -uuu and see where the file appears.