Linux, regardless of the distro you use, comes with a number of GUI tools which allow searching for files. Many modern file managers support file searching right in the file list. However, most of them do not allow you to search inside a file's contents. Here are two methods you can use to search for file contents in Linux.
Advertisеment
Probably, there are more methods available. There's Catfish, a popular search tool with a search index, which can find your files really quickly. It comes with an option to search for file contents, but it does not work reliably for me.
I would like to share the methods I use myself.
The first method involves the grep utility, which exists in any distro, even in embedded systems built on busybox.
To find files containing specific text in Linux, do the following.
- Open your favorite terminal app. XFCE4 terminal is my personal preference.
- Navigate (if required) to the folder in which you are going to search files with some specific text.
- Type the following command:
grep -iRl "your-text-to-find" ./
Here are the switches:
-i - ignore text case
-R - recursively search files in subdirectories.
-l - show file names instead of file contents portions../ - the last parameter is the path to the folder containing files you need to search for your text. In our case, it is the current folder with the file mask. You can change it to the full path of the folder. For example, here is my command
grep -iRl "linux" /home/user/Documents/winaero
Note: Other useful switches you might want to use with grep:
-n - show the line number.
-w - match the whole word.
Another method I use is Midnight Commander (mc), the console file manager app. Unlike grep, mc is not included by default in all Linux distros I've tried. You may need to install it yourself.
Find files containing specific text with mc
To find files containing some specific text using Midnight Commander, start the app and press the following sequence on the keyboard:
Alt + Shift + ?
This will open the search dialog.
Fill in the "Content:" section and press the Enter key. It will find all files with the required text.
You can place these files in the left or right panel using the Panelize option and copy/move/delete/view/do whatever you want them.
Midnight Commander is a very time-saving tool when it comes to search.
That's it.
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!
Advertisеment
The code that you provided helped me. There are also another commands which I cannot remember to find text in files but this one is made it quickly. I have bookmarked this post for further usage. Thank you.
WHAT ABOUT WINDOWS?!
I use Total Commander for that.
Thanks
Midnight Commander reminds me of XTree for DOS way, evidently, way way, back in the day!! :-) Anyone else remember!?
It reminds me of Norton Commander. Good days.