Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux find file names with given string recursively [duplicate]

Tags:

string

linux

find

People also ask

How will you find files recursively that contains specific words in their filename?

You can use grep command or find command as follows to search all files for a string or words recursively.

How do you search for the string in files of a directory recursively in Linux?

To recursively search for a pattern, invoke grep with the -r option (or --recursive ). When this option is used grep will search through all files in the specified directory, skipping the symlinks that are encountered recursively.

How do I search for a file name in a string?

You can use “grep” command to search string in files.

How do I find all files containing specific text on Unix?

Without a doubt, grep is the best command to search a file (or files) for a specific text. By default, it returns all the lines of a file that contain a certain string. This behavior can be changed with the -l option, which instructs grep to only return the file names that contain the specified text.


Use the find command,

find . -type f -name "*John*"

The find command will take long time because it scans real files in file system.

The quickest way is using locate command, which will give result immediately:

locate "John"

If the command is not found, you need to install mlocate package and run updatedb command first to prepare the search database for the first time.

More detail here: https://medium.com/@thucnc/the-fastest-way-to-find-files-by-filename-mlocate-locate-commands-55bf40b297ab


This is a very simple solution using the tree command in the directory you want to search for. -f shows the full file path and | is used to pipe the output of tree to grep to find the file containing the string filename in the name.

tree -f | grep filename

use ack its simple. just type ack <string to be searched>