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.RECOMMENDED:Probably, there are more methods available.
![]()
Find command donotprint/donotprintThe find command is used to find files on a Linux or Unix like system. It will search directories you specify for files that match the supplied search condition. A search condition can be used to search files by name, owner, group, type, permissions, date, time, case, and other criteria.
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. 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/winaeroNote: 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 mcTo 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.RECOMMENDED:You are here: » » Find Files Containing Specific Text in Linux.
Searching or finding files on a Linux system from the terminal can be a little of a challenge especially for newbies. However, there are several command line tools/utilities for locating files in Linux.In this article, we will review 5 command line tools to find, locate and search files quickly on Linux systems. Find Commandis a powerful, widely used CLI tool for searching and locating files whose names match simple patterns, in a directory hierarchy. Using find is simple, all you need to do is provide a starting point (top of the directory heirarchy) where the search beings. This can be the current directory or any other directory where you suspect the file you are looking for is stored.After the starting point, you can specify an expression (composed of test, actions, options and operators) which describes how to match files and what to do with the files that were matched.It supports multiple options to locate files using attributes such as permissions, users, groups, file type, date, size and other possible criteria. You can learn some useful find command usage examples in the following articles:.2. Locate Commandis another commonly used CLI utility for searching files quickly by name, just like find command.
However, it is practically more efficient and faster compared to its counterpart because, instead of searching through the file system when a user initiates a file search operation (the way find works), locate queries a database which contains bits and parts of files and their corresponding paths on the file system.This database can be prepared and updated using the updatedb command. Note that locate will not report files created after the most recent update of the relevant database.Read Also: 3. Grep CommandAlthough is not a tool for directly searching files (its instead used to print lines matching a pattern from one or more files), you can employ it to locate files. Assuming you know a phrase in the file(s) you are looking for or you are looking for a file that contains a particular string of characters, grep can help you list all files that contain a particular phrase.For example, if you are looking for a README.md file which contains the phrase “ An assortment”, which you suspect should be somewhere in your home directory, possibly in /bin, you can locate it as shown. $ grep -Ri /bin -e 'An assortment'OR$ grep -Ri /bin/ -e 'An assortment' cut -d: -f1Where the grep flag:.R – means search the specified directory recursively.i – means ignore case distinctions.e – specifies the phrase to be used as a pattern for searching.d – specifies the delimter.f – sets the field to be printedYou can learn some useful grep command usage examples in the following articles:.4. Which Commandwhich command is a tiny and straightforward utility for locating the binary of a command; it outputs the absolute path of a command. For example: $ which find$ which locate$ which which5.
Whereis Commandwhereis command is also used to locate a command and it additionally shows the absolute path of the source, and manual page files for the command. $ whereis find$ whereis locate$ whereis which$ whereis whereisRead Also:That’s all for now! If we have missed any Commandline tools/utilities for quickly locating files on a Linux system, let us know via the comment form below. You can ask any questions concerning this topic as well.
Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |