Dru Dru - 2 months ago 9x
Linux Question

Linux - Find Files with Name Containing String

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

commands that can find files beginning with something
or ending with something

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

For example, if
was a file in the current directory.

How could I return this file and others containing the string
? 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.