0
0
Linux CLIscripting~5 mins

grep -r for recursive search in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the -r option do in the grep command?
The -r option tells grep to search recursively through all files in the specified directory and its subdirectories.
Click to reveal answer
beginner
How would you use grep -r to find the word "apple" in all files inside the current directory and its subfolders?
You would run: grep -r "apple" . where . means the current directory.
Click to reveal answer
beginner
True or False: grep -r searches only text files by default.
False. grep -r searches all files, including binary files, unless you add options to exclude them.
Click to reveal answer
intermediate
What is the difference between grep -r and grep -R?
grep -r follows symbolic links only if they are on the command line, while grep -R follows all symbolic links recursively.
Click to reveal answer
intermediate
How can you limit grep -r to search only files with a specific extension, like .txt?
You can combine grep -r with --include="*.txt" like this: grep -r --include="*.txt" "pattern" .
Click to reveal answer
What does the command grep -r 'hello' /home/user do?
ALists all files in /home/user
BSearches for 'hello' in all files inside /home/user and its subdirectories
CDeletes files containing 'hello' in /home/user
DSearches for 'hello' only in the /home/user directory files, not subdirectories
Which option makes grep follow all symbolic links recursively?
A-v
B-r
C-i
D-R
How do you search recursively for the word 'error' only in files ending with '.log'?
Agrep -r 'error' --include='*.log' .
Bgrep 'error' *.log
Cgrep -r 'error' *.log
Dgrep --include='*.log' 'error'
True or False: grep -r will skip binary files by default.
AFalse
BTrue
COnly on Linux
DOnly with extra options
What symbol represents the current directory when using grep -r?
A~
B/
C.
D..
Explain how to use grep -r to find a word inside all files in a folder and its subfolders.
Think about how to tell grep to look inside folders and subfolders.
You got /4 concepts.
    Describe the difference between grep -r and grep -R regarding symbolic links.
    Consider how each option treats links to other files or folders.
    You got /3 concepts.