Introduction to Grep(g/re/p) and 10 Useful Commands

$ grep "string_to_search" filename
$ grep "string_to_search" *
$ grep -r "string_to_search" *
$ grep "lines.*empty" filename
  • . — matches any single character.
  • ? — The preceding item is optional and matched at most once.
  • * — The preceding item is matched zero or more times.
  • + — The preceding item will be matched one or more times.
  • {n} — The preceding item is matched exactly n times.
  • {n,} — The preceding item is matched n or more times.
  • {,m} — The preceding item is matched at most m times.
  • {n,m} — The preceding item is matched at least n times, but not more than m times.
$ grep -iw "string_to_search" filename
$ grep -C 2 "string_to_search" filename
$ grep -v "string_to_search" filename
$ grep -v -c "string_to_search" filename
$ grep -r -l "string_to_search" /var/log/*
$ grep -n "string_to_search" filename
$ ifconfig | grep 192.168

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store