Tuesday, 16 October 2012

Using grep to Find Files on Linux (Case Insensitive Search)


I learnt a few new Linux search commands today.

First cd to the directory you want to look through and then...
  • If you want to output the context of the matched line inside a file in a directory use:
grep --before-context=3 --after-context=3 -i "search text" *
  • If you want to output a list of matched files in a directory use:
  • grep -l -i "search text" *
    • -i makes the search case insensitive
    • -l lists all matched files
    • --before-context=num gives the context lines before the matched element
    • --after-context=num gives the context lines after the matched element



    1 comment:

    1. There are certain things I don't want to joke about. If it's about somebody else, it's fine. If it's about me, I think it's totally insensitive! See the link below for more info.

      #insensitive
      www.ufgop.org

      ReplyDelete

    Please leave your thoughts and comments!