$ grep -Rinw ~/bin/ -e 'check_root' -e 'netstat' In addition, it is possible to search for more than one pattern, using the following command. $ grep -Rnw -include=\*.sh ~/bin/ -e 'check_root' This example instructs grep to only look through all. The command below will search within the current directory. Additional information See the grep command page for additional information and help with this command. grep -r 'computerhope' /www/ In the above example, grep searches the /www/ directory and all subdirectories for the text 'computerhope' and returns any results found. The ack command is likely the fastest searching tool, but it’s not as popular as the above options. To do this, youd type a command similar to the following example. Using ack to Find a Specific Word in a File. The normal grep flags should be fully operational from within the -exec flag. $ grep -Rinw ~/bin/ -e 'check_root'Īssuming there are several types of files in a directory you wish to search in, you can also specify the type of files to be searched for instance, by their extension using the -include option. That’s why grep is required to search file text and contents. If you want to know the exact line where the string of text exist, include the -n option. To ignore case distinctions employ the -i option as shown: $ grep -Riw ~/bin/ -e 'check_root' You should use the sudo command when searching certain directories or files that require root permissions (unless you are managing your system with the root account). Where the -R option tells grep to read all files under each directory, recursively, following symbolic links only if they are on the command line and option -w instructs it to select only those lines containing matches that form whole words, and -e is used to specify the string (pattern) to be searched. To find a word or phrase, press / on your. The command below will list all files containing a line with the text “ check_root”, by recursively and aggressively searching the ~/bin directory. If you have a large text file or are trying to find a specific piece of text, you can do that easily in less. Read Also: 11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions This article will guide you on how to do that, you will learn how to recursively dig through directories to find and list all files that contain a given string of text.Ī simple way to work this out is by using grep pattern searching tool, is a powerful, efficient, reliable and most popular command-line utility for finding patterns and words from files or directories on Unix-like systems. grep is your best friend when it comes to finding a string in a file. Do you want to find all files that contain a particular word or string of text on your entire Linux system or a given directory. Let us go through some of the commands you will need to perform this task and then finally construct a single liner to do the job.