grep command

grep is the most use in unix os. i give some examples about grep using.


this is hello world of grep command. it search first argument in second argument directory.
  • grep borjune /etc/passwd

if it is called with -i argument, it ignores lower and upper case.
  • grep -i borjune /etc/passwd

-r argument is recursion argument. it search first argument in all directories in second argument directory.
  • grep -r borjune /etc/passwd

when grep is called with -w argument, it search just first argument in directory, prevents words which contains first argument.
  • grep -w borjune /etc/passwd

-c argument returns count of first argument in directory.
  • grep -c borjune /etc/passwd

-n argument finds first argument in second argument and gets their line numbers.

  • grep -n borjune /etc/passwd

-v argument reverse process logic of plain grep command, it gives lines which don't contain first argument.

  • grep -v borjune /etc/passwd

-l argument list results.
  • grep -l borjune /etc/passwd

–color argument colourize lines.

  • grep --color borjune /etc/passwd 

-E parameter is used for extended grep operations. Its alias is egrep.
  • grep -E 'word1|word2' directory


Popular posts from this blog

Polya’nın Problem Çözme Teknikleri

Mikroislemci Temelleri