What is grep in linux

Asked By 0 points N/A Posted on -
qa-featured

What is grep in Linux and how do you use it?

SHARE
Best Answer by Odtohan vasko
Best Answer
Best Answer
Answered By 10 points N/A #110974

What is grep in linux

qa-featured

 

Hi Chase Dean,

Grep is a command line in Linux which searches the lines which matches the given criteria in folder or given file. Grep shows the matching lines by default but specific operational modes can be choose. This is a very useful tool to search data from PC even if you don’t know where it is stored. Originally grep was prepared for UNIX but it also works on UNIX like systems.

If you write .mp3 in grep regex, it will search each line of file to find .mp3 and will show the lines containing this so grep is a line based. Search pattern is case sensitive by default so it cant find Cat (with capital C) if you searched cat (with c).

Gep command line

Grep ‘ word ‘ filename

Grep ‘ jaz jaz2 ’ filename

Cat other file I grep ‘anything’

Command I grep ‘anything’

Command optional I grep ‘data’

Grep – colour ‘data’ filename

Answered By 590495 points N/A #110975

What is grep in linux

qa-featured

In Linux, when using the grep command, it searches the specified file for a match to the given words or strings. By default, grep displays the matching lines. Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines. Here is the command syntax for grep:

  • grep 'word' filename
  • grep 'string1 string2'  filename
  • cat otherfile | grep 'something'
  • command | grep 'something'
  • command option1 | grep 'data'
  • grep –color 'data' filename

For example, to search /etc/passwd for boo user, you can enter:

$ grep boo /etc/passwd

You can also force grep to ignore the casing of the words by using the option “-i”:

$ grep -i "boo" /etc/passwd

For additional information regarding this matter, you may visit HowTo: Use grep Command In Linux.

Related Questions