[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedJanuary 30, 2023

How To Use grep Command In Linux

How To Use Grep Command In Linux

Grep is an essential Linux and Unix command. It is used to search text and strings in a given file. In other words, grep command searches the given file for lines containing a match to the given strings or words.

The syntax is as follows:

grep 'word' filename
fgrep 'word-to-search' file.txt
grep 'word' file1 file2 file3
grep 'string1 string2'  filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName
grep [-options] pattern filename
fgrep [-options] words file

 

How to use grep recursively

You can search recursively i.e. read all files under each directory for a string “192.168.1.5”

$ grep -r "192.168.1.5" /etc/

OR

$ grep -R "192.168.1.5" /etc/

Sample outputs:

/etc/ppp/options:# ms-wins 192.168.1.50
/etc/ppp/options:# ms-wins 192.168.1.51
/etc/NetworkManager/system-connections/Wired connection 1:addresses1=192.168.1.5;24;192.168.1.2;

You will see result for 192.168.1.5 on a separate line preceded by the name of the file (such as /etc/ppp/options) in which it was found. The inclusion of the file names in the output data can be suppressed by using the -h option as follows:

$ grep -h -R "192.168.1.5" /etc/

OR

$ grep -hR "192.168.1.5" /etc/

Sample outputs:

# ms-wins 192.168.1.50
# ms-wins 192.168.1.51
addresses1=192.168.1.5;24;192.168.1.2;
Keep reading
How to Rename Files and Directories.
June 26, 2023

How to Rename Files and Directories.

How To Rename Files And Directories. In this tutorial, we will show you how to use the mv and rename commands to rename files and directories. Renaming Files with the mv Command The mv command (short of move) is used to rename or move files from one location to another. The syntax for the…

Read article
How to create bash alliases.
June 26, 2023

How to create bash alliases.

How To Create Bash Alliases. This article explains how to create bash aliases so you can be more productive on the command line. Creating Bash Aliases Creating aliases in bash is very straight forward. The syntax is as follows: alias alias_name=”command_to_run” An alias declaration starts with the…

Read article
How to use file comand.
June 22, 2023

How to use file comand.

How To Use File Comand. The file command displays the type of a file. Linux File Command Syntax The syntax for the Linux file command is as follows: file [OPTION] [FILE] It can take one or more file names as its arguments. How to Use the file Command to Find the File Type…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00