Linux Piping Output With Grep
Using the pipe operator ‘|’, you can send data from program to another. This example will show how to search for all files with ‘test’ in the name. It returns the names latest, test2.txt and test3.txt.
Search the current directory for files with the string ‘test’
root@vps [~]# ls | grep test
Searching A Single File for a String
root@vps [~]# grep "kent" newfile.txt
My name is kent.
Searching All Files for Strings
root@vps [~]# grep -r "kent" .
./.bash_history:ls | grep kent
./.bash_history:grep kent newfile.txt
./.bash_history:grep kent ls
./.bash_history:grep -r kent
./.bash_history:grep -r "kent"
./newfile.txt:My name is kent.