• Beginning Grep for Linux SysAdmins

    GNU grep is an amazing power tool for finding words, numbers, spaces, punctuation, and random text strings inside of files, and this introduction will get you up and running quickly.

    We'll stick to GNU grep and the Bash shell, because both are the defaults on most Linux distros. You can verify that you have GNU grep, and not some other grep:

    $grep -V
    grep (GNU grep) 2.21
    Copyright (C) 2014 Free Software Foundation, Inc.


    Basic grep

    We humans tend to think in terms of the numbers, words, names, and typos we want to find, but grep doesn't know about these things; it looks for patterns of text strings to match. That is why you see the phrase "pattern matching" when you're studying grep and other GNU text-processing tools.

    I suggest making a plain text file to use for practicing the following examples because it limits the scope, and you can quickly make changes.

    Most of us know how to use grep in simple ways, like finding all occurrences of a word in a file. First type your search term, and then the file to search:

    Läs hela artikeln.



    Photo credit: Carla Schroder
    .