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*" -printIt will find all files in the current directory (delete
maxdepth 1if 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 "*:*" -printIf 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 touchBut, I repeat,
findis a better and cleaner solution for your task.