![]() ![]() What if we want to do the opposite that’s, print all lines that do not match the search pattern. In the output screen, we have all the words containing exam printed and highlighted in red. We run: $ grep –r "exam" /home/imohweb grep -r flag command In this example we’re printing all files that contain the string exam in /home/imohweb directory. This is especially useful when you don’t know which file contains the specific pattern that you are looking for. ![]() The grep –r can be used to search for a pattern recursively within the directory. The output above detected the word "Pass" as case sensitive and highlighted in red. The grep command is case sensitive and will only print the line matching the case of the pattern. This will print out the word matching the search pattern which is second. In above output screen, the word "second" is the word we searched for while the techdirectarchive.txt is the filename. $ grep second techdirectarchive.txt The grep command output screen Before I proceed, if you are just getting started with Linux In this write-up, I will take you through how to use the locate, find and the grep command to search for files and patterns in Linux/Unix-like OS. kindly refer to the following related guides: How to install and remove Microsoft Edge Browser on Linux, how to install and configure BigBlueButton on Ubuntu Linux 16.04 LTS Xenial Xerus, How to setup SELinux on a Linux server, a brief introduction to Linux, and how to create disk partition in Ubuntu Linux and how to create, edit, save a file and quit Vim Editor in Linux. There are several commands on Linux systems that allow you to search for files, with find and locate being the most used ones while the grep command is a search utility used primarily to return lines from a file, or files, that match a particular search term. When it comes to using Linux one of the most common operations is to search for files and directories. Files in Linux can be searched by a single line of command. ![]()
0 Comments
Leave a Reply. |