There are many command line utilities offered by the Unix based machines; each one of them can be utilized to accomplish a certain task. Been using linux for quiet some time now, I am really glad about the command line based tools offered by it, utilities which can be used through the terminal application.
Through this article, I am going to teach you how to make use of the grep utility in your Unix based machine. First, let me share some general information about this utility.
According to the official manual, the grep utility searches any given input files, selecting lines that match one or more patterns. The grep tool is used for simple patterns and basic regular expressions.
Let’s take a practical example. Suppose that you want to find out if a file exists or not in a specific directory.
The first thing that you need to do is to list the files inside the directory, and later make use of the grep utility to match the specific file.
Based on my personal experience, the following is the command which should be run in the terminal application.
ls | grep file_here
I have many files in my Desktop, the one I care about right now is the favorite.jpg. Is it still in there?
The following command can help me to find out.
ls | grep favorite.jpg
If the file exists in the Desktop folder, then the following will come out on the console.
As you can see from the above output, when the grep utility matches the input it is looking for, it displays the result on the console application.
The grep utility is very useful to the computer geek, especially when they need to search for files based on a pattern.