Linux Sysadmin Test Prep

grep

grep

To grep is to Globally search for a Regular Expression and Print matching lines.

There are a few implementaions of grep, egrep "extended grep" being the most important.

grep

grep -r content -l / --exclude-dir=public (recursive grep for content in / and list filename)

grep -w word file.txt (grep exact word)

grep -v junk file.txt (grep lines WITHOUT junk)

grep "this\|that" file.txt (grep for this OR that)

grep -v junk file.txt | grep content (grep for content without junk)

grep cont.nt file.txt (grep for word with unknown single character)

grep [uo]n file.txt (grep for un OR on)

grep [^uo]n file.txt (grep for anything before n except u and o)

ls -l /etc | grep rc[0-9] ( grep for numbered rc files in /etc; same result as using [[:digit:]])

grep "kubelet\[[[:digit:]]\+\]" /var/log/syslog

grep "\([pP]ost\( *\|\-\)[mM]odern\)" file.txt (grep post modern, post-modern, PostModern)


  1. Create a symlink to the file /danielsTestDrills/quizFiles/quiz to a folder in your PATH.
  2. Prepare the GPL-3 file:
  • Assuming you are on Ubuntu: Locate the "GPL-3" license file and copy it to /danielsTestDrills/GPL-3.
  • Otherwise: Save the file https://www.gnu.org/licenses/gpl-3.0.txt to /danielsTestDrills/quizFiles/GPL-3
  1. Download the word list: Save the file https://raw.githubusercontent.com/dwyl/english-words/master/words.txt to /danielsTestDrills/quizFiles/WORDS
  2. Run quiz with the argument grep
  3. Run quiz with the argument egrep
Edit this page on GitHub

On this page