

Note: Other useful switches you might want to use with grep:Īnother method I use is Midnight Commander (mc), the console file manager app. For example, here is my command grep -iRl "linux" /home/user/Documents/winaero
GREP FIND IN FILES FULL
You can change it to the full path of the folder. In our case, it is the current folder with the file mask. the last parameter is the path to the folder containing files you need to search for your text.

l - show file names instead of file contents portions. R - recursively search files in subdirectories.

Type the following command: grep -iRl "your-text-to-find".Navigate (if required) to the folder in which you are going to search files with some specific text.XFCE4 terminal is my personal preference. To find files containing specific text in Linux, do the following. The first method involves the grep utility, which exists in any distro, even in embedded systems built on busybox. I would like to share the methods I use myself. It comes with an option to search for file contents, but it does not work reliably for me. There's Catfish, a popular search tool with a search index, which can find your files really quickly. You may also want to check out ripgrep, a line-oriented search tool that recursively searches the current directory for a regex pattern that comes with some extra features, and is very fast.Probably, there are more methods available. Here, 7 is the line number on which the pattern we've searched for ( text) was found.įor more information and advanced usage, see the grep man page. home/logix/Documents/test/folder/file2.txt:7:text Grep -Rni -exclude-dir= 'text' ~/DocumentsĮxample output: /home/logix/Documents/test/folder/file1.js:7:text In that case, the command you'd need to use would be (this is a single command): Also, you want to show the line numbers ( -n), search recursively and also follow all symbolic links ( -R). Let's say you want to find all files containing the case-insensitive ( -i) text in the ~/Documents folder and its subfolders except for the Private and Personal subfolders ( -exclude-dir), and only search in the files that have the. Let's take a look at an example which combines these command line flags. -exclude-dir=GLOB is used to exclude folders from being searched.-include=GLOB / -exclude=GLOB includes or excludes certain files.Depending on the number of files, this can slow down the search, so take this into consideration when using it -i performs the search case-insensitive (it's case-sensitive by default).When a match is found, besides the file path in which it was found, grep will also display the line number on which the pattern was found Grep has many options, but below I'll only list a few that you might find especially useful when trying to find all files containing specific text on Linux (besides those already mentioned above):
GREP FIND IN FILES HOW TO
You might also be interested in: How To Repeat A Command Every X Seconds On Linux If you don't want to search in the current folder, but in a specific folder, you can specify the path in which grep should look into, by adding it at the end of the command, like this: If you only want to list the filenames containing the exact whole word text (as opposed to the default partial word matching), and not things like texting, 123text, and so on, you'd need to append the -w (whole words) command line option, like this: If you require following all symbolic links, use -R instead of -r. r stands for recursive, reading all the files in the directory and its subdirectories. This includes strings like texting for example, because it contains our search pattern, text. This lists all the files in the current folder and subfolders containing text. To do this, you need to open the terminal, navigate to the folder where you want to perform the search, and run: Say you want to search for the word text (case-sensitive!) in all the files in the current directory and its subdirectories. Grep is a command-line utility which prints lines that match a given pattern, and should be installed by default. For this we'll use grep, a standard Unix program. This article explains how to find all files containing specific text on Linux.
