Find all files with name containing string [closed]
Solution 1:
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.
Solution 2:
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.
Solution 3:
The -maxdepth
option should be before the -name
option, like below.,
find . -maxdepth 1 -name "string" -print