From the course: Linux: Kernels and Logging for System Administration

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Search log files

Search log files - Linux Tutorial

From the course: Linux: Kernels and Logging for System Administration

Start my 1-month free trial

Search log files

- [Instructor] The most efficient way of searching for data in a file is to use grep. Grep shows lines in the file that match the provided search criteria. The syntax for grep is grep, space, options, space, the search criteria, and then the file name. Options that I find useful are - i for case insensitive searches, -v for inverted searches, which shows the opposite of the search criteria, - c for the number of lines that matched, - o to show only the characters that matched, not the entire line, -r for recursive grep, this searches through all files in a directory, and lastly, -E to use extended regular expressions. This is the same as using egrep. There are many more options, view the grep man page for more information. This example shows a case insensitive search for the word root in /etc/passwd. We can also pipe the output of any of the command into grep. This is a very common use for grep. In this example, I'm using the find command to search for files in the entire operating…

Contents