Linux grep command

When you’re searching for a text in a particular file under a Linux system you’re usually using the grep command. grep stands for Get Regular Expression and Print, in this article we’ll show several examples of how to use it:

Using grep for a basic search

grep "textToSearchFor" file.txt

grep for a case-insensitive search

grep -i "THIS CASING DOESN'T MATTER" file.conf

grep without matching

grep -v "thisWillNotBeMatched" file.txt

grep for word matching

Usually, grep searches like how you would match a Regular Expression (as it’s in its name), if you would like to apply \b search you would use

grep -w "justThisWordWillBeMatched" file.cnf

grep for to count the number of occurrences

grep -c "howManyTimesThisAppearsInTheFile" file.php

grep with line numbers

This will show the number of the line the match is found

grep -n "whichLineIsThisOn" file.txt
  • 0 Los Usuarios han Encontrado Esto Útil
¿Fue útil la respuesta?

Artículos Relacionados

Linux tar Command

The Linux tar command is used to compress and extract files to and from an archive. In this...

Linux file command

The file command is used to check a file’s type and contents in Linux environment. It is most...

Linux export command

When you’re managing your shell’s variables and you wish to save them to your environment you can...

Linux su command

The su command is most commonly used to switch to another user. You will then be able to run...

Linux wc command

If you’re interested in finding the word count or lines of a file in your Linux environment you...

Powered by WHMCompleteSolution