Using grep command

Analyze and store logs

    Using grep command

  •             The grep command is used to search text from the file or lines. By default, grep displays the matching lines. It is one of the most useful commands on UNIX and Linux operating systems.


    grep 'word' filename
    grep 'word' file1 file2 
    grep 'string1 string2'  filename
    command | grep 'something'
    grep --color 'data' filename

    To find log entries:

    grep -i - ignores case when searching
    (example: grep -i oct /var/log/secure)
    grep -v - displays all but matched lines. Useful when you want to exclude some patterns
    (example: grep -v Oct /var/log/secure # excludes October from the log file)
    grep -e - matches regular pattern against the text)
    (example: grep -e "^$" file # find all the empty lines in the file)
    grep -c - prints only the number of matched lines

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy