Linux Basics

45 / 107

Use grep command

If you want to locate a word in files, you can use the grep command. Grep lists all the lines from files in which a particular word exists. Examples of grep

grep myword file1 file2

If you want to search in files recursively - inside every subdirectory of a directory, use the following command

grep -r myword directory

If you want to search case insensitive, use -i switch

grep -i myword file1 file2

Practical Use Cases

grep is a very powerful tool. It can somewhat behave like where clause in SQL queries.

Few Examples are:

  1. On a web server, you could filter only the errors from a log file
  2. Say you have a directory containing the temperature of various cities and you are looking for temperatures of the city having the name as nyc, you could easily do: grep nyc tempdirectory/*

No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...