0

I run this command

find -iname *something*

It normally searches in subfolders but if I have a file that matches the criteria in the working directory it only reports it and stops. I'm thinking to write a function that first searches sub folders in current directory than issue many find commands for each of them but I feel there should be an easier way... Actually I think it should be the default behavior, so maybe I have something wrong in some setup file?

  • 2
    do you have it aliased or hidden with a function? alias find and declare -f find output would clarify the situation – Jeff Schaller Aug 26 '16 at 17:51
  • 1
    What happens when you add a dot after find - find . -iname something ? – fd0 Aug 26 '16 at 17:53
6

Does something include a glob that is being interpreted by the shell? That would cause the expanded filename to be passed to the find command.

For example if you run find -iname *.txt with a file in the current directory called file.txt then the resulting command after shell expansion would be find -iname file.txt.

To avoid this pitfall you can escape the glob to send the literal string to the find command with find -iname '*.txt'

0

If the subfolders are behind symbolic links you have to use the -L option. Try

find -L . -iname '*something*'

According to the find man pages

If -L is in effect and find discovers a symbolic link to a subdirectory during its search, the subdirectory pointed to by the symbolic link will be searched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.