# Grep Command in Linux

# Grep Command

The Grep command can find or search a regular expression or a string in a text file. To demonstrate this, let’s create a text file ***welcome.txt*** and add some content as shown.

```bash
Welcome to Linux !
Linux is a free and opensource Operating system that is mostly used by
developers and in production servers for hosting crucial components such as web
and database servers. Linux has also made a name for itself in PCs.
Beginners looking to experiment with Linux can get started with friendlier linux
distributions such as Ubuntu, Mint, Fedora and Elementary OS.
```

Great! Now we are ready to perform a few grep commands and manipulate the output to get the desired results. To search for a string in a file, run the command below **Syntax**

```bash
$ grep "string" file name
```

or

```bash
$ filename grep "string"
```

Example:

```bash
$ grep "Linux" welcome.txt
```

Output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682275722618/d5fe9c63-3437-49d8-aede-a75b31c2c5a8.png align="center")

As you can see, grep has not only searched and matched the string “Linux” but has also printed the lines in which the string appears. If the file is located in a different file path, be sure to specify the file path as shown below

## [Colorizing Grep results using the --color option](https://www.digitalocean.com/community/tutorials/grep-command-in-linux-unix#colorizing-grep-results-using-the-color-option)

If you are working on a system that doesn’t display the search string or pattern in a different color from the rest of the text, use the `--color` to make your results stand out. Example

```bash
$ grep --color "free and opensource" welcome.txt
```

Output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682276020975/92aebf71-3ead-49c8-b4a6-652075aebfc9.png align="center")
