Linux finds file names with a given string

I'm on Ubuntu and I would like to find all the files in the current directory and subdirectories whose name contains the string "John". I know that grep can match the contents in files, but I have no idea how to use it with file names. Any help would be appreciated.

+86
string linux find
Oct 29 '12 at 23:17
source share
5 answers

Use the find command ,

 find . -type f -name "*John*" 
+159
Oct 29 '12 at 23:19
source share

The correct answer has already been set, but in order to learn how to help myself, I thought that I would choose something useful in a different way; if you can summarize what you are trying to achieve in one word, Linux has a powerful help function.

 man -k <your search term> 

What this means is to list all the teams that have a search query in the short description. This is usually a pretty good chance that you will find what you need.;)

This conclusion can sometimes be somewhat overwhelming, and I would recommend narrowing it down to executable files rather than all available man pages, for example:

 man -k find | egrep '\(1\)' 

or, if you also want to search for commands that require higher privilege levels, for example:

 man -k find | egrep '\([18]\)' 
+23
Oct 30
source share

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

+1
Sep 12 '14 at 4:03
source share

The find will take a long time, as it scans real files in the file system.

The fastest way is to use the locate command, which will immediately give the result:

 locate "John" 

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

More details here: http://itblog.study.land/the-fastest-way-to-find-files-by-filename-mlocate-locate-and-updatedb-commands-2/

+1
May 18 '16 at 3:50
source share

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

 tree -f | grep filename 
0
Nov 24 '16 at 14:25
source share



All Articles