Find all files with name containing string

linux find all files containing string
linux find filename containing string recursively
awk find files containing text
unix command to find a string in all files in a directory
find string in all file
find string in multiple files
find a file containing string
grep find all files with text

I have been searching for a command that will return files from the current directory which contain a string in the filename. I have seen locate and find commands that can find files beginning with something first_word* or ending with something *.jpg.

How can I return a list of files which contain a string in the filename?

For example, if 2012-06-04-touch-multiple-files-in-linux.markdown was a file in the current directory.

How could I return this file and others containing the string touch? Using a command such as find '/touch/'

Use find:

find . -maxdepth 1 -name "*string*" -print

It will find all files in the current directory (delete maxdepth 1 if you want it recursive) containing "string" and will print it on the screen.

If you want to avoid file containing ':', you can type:

find . -maxdepth 1 -name "*string*" ! -name "*:*" -print

If you want to use grep (but I think it's not necessary as far as you don't want to check file content) you can use:

ls | grep touch

But, I repeat, find is a better and cleaner solution for your task.

Linux find file names with given string, I'm on Ubuntu, and I'd like to find all files in the current directory and subdirectories whose name contains the string "John". I know that grep can  Use find: find . -maxdepth 1 -name "*string*" -print. It will find all files in the current directory (delete maxdepth 1 if you want it recursive) containing "string" and will print it on the screen. If you want to avoid file containing ':', you can type: find . -maxdepth 1 -name "*string*" ! -name "*:*" -print

Use grep as follows:

grep -R "touch" .

-R means recurse. If you would rather not go into the subdirectories, then skip it.

-i means "ignore case". You might find this worth a try as well.

Find files containing string in file name and different string within file , That's because grep can't read file names to search through from standard input. What you're doing is printing file names that contain XYZ . The code bellow asks for a folder location, and then for a string. Then it searches through the files in that folder and returns a list of those, that contain the given string.

The -maxdepth option should be before the -name option, like below.,

find . -maxdepth 1 -name "string" -print

How do I find all files containing specific text on Linux?, I'm trying to find a way to scan my entire Linux system for all the files containing a in files would be Just to clarify, I wanted a text within the file, not in the file name. You can use “grep” command to search string in files. List file names for all files containing pattern: Get-ChildItem -Recurse filespec | Select-String pattern | Select-Object -Unique Path ls -r filespec | sls pattern | select -u Path; List FileInfo objects for all files not containing pattern: Get-ChildItem -Recurse filespec | Where-Object { !(Select-String pattern $_ -Quiet) } ls -r filespec | ? { !(sls pattern $_ -q) }

find $HOME -name "hello.c" -print

This will search the whole $HOME (i.e. /home/username/) system for any files named "hello.c" and display their pathnames:


However, it will not match HELLO.C or HellO.C. To match is case insensitive pass the -iname option as follows:

find $HOME -iname "hello.c" -print

Sample outputs:


Pass the -type f option to only search for files:

find /dir/to/search -type f -iname "fooBar.conf.sample" -print
find $HOME -type f -iname "fooBar.conf.sample" -print

The -iname works either on GNU or BSD (including OS X) version find command. If your version of find command does not supports -iname, try the following syntax using grep command:

find $HOME | grep -i "hello.c"
find $HOME -name "*" -print | grep -i "hello.c"

OR try

find $HOME -name '[hH][eE][lL][lL][oO].[cC]' -print

Sample outputs:


Finding a File Containing a Particular Text String In Linux Server , Task: Only display filenames. By default, the grep command prints the matching lines. You can pass -H option to print the filename for each match  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

If the string is at the beginning of the name, you can do this

$ compgen -f .bash

How to find files with Matching String in Linux, This option of grep only shows filenames that contain matching text. Btw, a good knowledge of essential Linux commands like find, grep, awk, and sed goes a  The Select-String cmdlet searches for text and text patterns in input strings and files. So if you are just looking to match with file names just use -Filter of Get-ChildItem or post process with Where-Object Get-ChildItem -Path $path -Recurse -Filter "*sample*" That should return all files and folders that have sample in their name.

How to find all files with a specific text using Linux shell , The output shows filenames as well as prints the actual line containing requested string. SUBSCRIBE TO NEWSLETTER Subscribe to Linux  In the “Indexing Options” window, click the “Advanced” button. In the “Advanced Options” window, switch to the “File Types” tab. Select the extension for the file type you would like to include in content searches, and then select the “Index Properties and File Contents” option under the list.

grep just file name containing a string (GNU/Linux forum at , how would I search all the directories for the file containing vim? I know I can use the command find . -name "Isee*" and that would display all,  The * character used as wildcards allow for any characters before or after the 1218 and the .pdf limits the actual searching to only Portable Document Format files (pdf's). Another way would be to search with these criteria: IMG*1218*.* This would find all file types (the portion of the file name after the last dot which contained IMG and 1218

command to find files by searching only part of their names?, Finding Files with bat Anywhere. To find all files anywhere inside /path/to/folder whose names contain bat , you can use: find /path/to/folder 

  • the question is confusing. do you want to find files which contain a string, or files whose names contain said string? the first question is answered with man grep, the second with man find. why would you google instead of using man, i don't know.
  • Thanks! The first sentence did not specify whether is was file contents or a filename. Updated.
  • Thanks @Zagorax. This does it exactly. Wish the command wasn't so long but ayee :)
  • @Dru, Modified to cover the case if you want to avoid colons. find is a very powerful tool, it must be somehow 'long'. :)
  • Thanks the first one did it perfectly without returning any content.
  • @Dru, if you want it 'shorter' you can avoid -print as this is the default behaviour and . as this is the default folder where it checks.
  • find . -name "*string*" Works great too. Removing . throws an error on my end. Thanks again @Zagorax.
  • Great. I noticed that some file contents follow a :. Is there anyway to withhold that? Using an option perhaps?
  • Try: grep -R "touch" . | cut -d ":" -f 2
  • That seems to only produce the contents of the files. You essentially answered my question though, I can try to do some digging for withholding the contents.
  • Ah... you only need the file names? Run :grep -R "touch" . | cut -d ":" -f 1 (sorry must have misread you).
  • Thanks @carlspring this is interesting. grep either returns files with contents and filenames containing touch or contents containing touch, I'm not sure which is the case, yet. Of the list of files returned, half contain touch in the title and the other half conatains touch in the body, not the title. Just realized this.