In this brief article, I present 10 essential Linux questions along with their answers.
This foundational knowledge is crucial for anyone seeking to master Linux.
Grep Command (Global Regular Expression Print)
Q1: How do you find a specific word in a log file using grep?
grep "word" logfile
Q2: How do you search recursively for a string inside all files in a directory?
grep -r "word" directory/
Q3: How do you display only the names of files that contain a specific string?
grep -l "word" *
Q4: How do you find lines that do NOT contain a specific pattern?
grep -v "pattern" filename
Q5: How do you count the number of occurrences of a word in a file?
grep -c "word" filename
Q6: How do you print lines before and after a matching pattern?
grep -B 3 -A 3 "pattern" filename
Q7: How do you use grep with multiple patterns?
grep -e "pattern1" -e "pattern2" filename
Q8: How do you perform a case-insensitive search?
grep -i "word" filename
Q9: How do you filter grep results further using awk or sed?
Pipe the output into awk or sed:
grep "pattern" file | awk '{print $1}'
Q10: How do you use grep to find an exact whole word match?
grep -w "word" filename
Stay tuned for part 4 coming tomorrow!
Connect with me on LinkedIn
#30DaysLinuxChallenge #RedHatEnterpriseLinux
#CloudWhistler #CloudEngineer #Linux
#DevOps #RedHat #OpenSource
#CloudComputing #Automation
#CloudEngineer