#How to search for text in files in current directory linux code#
The output file list includes plain text, scripts, formatted text, and source code files. If you have to search for files containing some specific text in a directory, which may have sub-directory with files or more sub-directories, then we can do so by using the recursive flag with the grep command. The grep command needs to be modified accordingly, putting the other character used as a separator in place of “:”. In the rare case in which some of the files contain the character “:” as part of their name, we can use the -F argument of the file command to use some character other than the “:” character as the separator. Different distros and desktop environments have their own software, so it’s impossible to write a guide that will cover them all. Searching for a text string in vim Search a file for a text string via GUI There are tons of GUI text editors available for Linux. In other words, the expression means “search for a : in the file command output followed by any number of characters “.*” and then the sub-string ” text”. All you need to do is type :/ followed by your search string, then press Enter. The expression “.*” ensures that the sub-string ” text” is only searched in the file type description, not in the filename. The subsequent grep command filters all files with “ASCII text” or “UTF-8 Unicode text” as part of the file type description. The file * command prints a list of filenames followed by the file type description of all files in the current directory. We can quickly list all text files in the current directory using a simple command: file * | grep ".* text" If our interest is only in files in the current directory, then the command is effortless.