There are 2 debian servers (packages for both are the same and versions 8.4) with find 4.4.2.
For some reason, on one find / -iname *her* searches for everything regardless of the register, but on the second - it does not search. Why?

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

The short answer is to take quotes. That is, write like that

 find / -iname "*his*" 

Why it happens? just the bash will produce a star and try to resize the template. And on the second server it happened by chance that a directory / file was found that matches the name. That is, if the "*his*" mask is the 'tohis.txt` file, then the above command will simply turn into

 find / -iname "tohis.txt" 

and will search for the specified file. And is he - who knows?

  • It really works. Hmm, but I can't understand why he is looking for on one server without quotes, but not on the second :( - user212017
  • Show the output of ls / on each server - I will indicate the reason. And the exact mask you use to search. - KoVadim
  • In general, I was looking for the pearl module curl here: find /usr/lib/x86_64-linux-gnu/perl5/5.20/auto/WWW/Curl/ -iname *curl* and there it is - Curl.so, but for some reason find He does not see it if you do not specify quotes ... - user212017
  • @ user212017, but not on the second - because in the directory where you issue this command, there is a file / directory whose name corresponds to the regular expression *her* (that is, the name contains the string her ). - aleksandr barakin
  • @alexanderbarakin with asterisks is not a regular expression. - KoVadim

and the second is not looking. Why?

probably because on the second server in the directory from which you run the command, there is one file or directory whose name matches the pattern you specify *her* .

in order to avoid this, it is necessary:

  • or escape meta characters ( * , ? , [ ) with a backslash: \*her\*
  • or enclose the entire parameter in quotes (better - single): '*her*'

I will illustrate visually the work of the so-called. pathname expansion mechanism, which is implemented in any posix-compatible shell.

  1. create an empty directory and make it current:

     $ mkdir /tmp/test; cd /tmp/test 
  2. Let's see what the shell does with the *her* parameter in this situation:

     $ echo *her* *her* 

    as you can see, no transformations have been done - the parameter was passed to the echo program (to be more precise, then, most likely, to the internal shell command, but in this case it is irrelevant) "as is".

  3. create a file containing the string her in the title:

     $ touch father 
  4. and repeat the same command:

     $ echo *her* father 

    as we see, the parameter *her* has turned into the father parameter!

  5. and if you create some more files containing the string her in the names:

     $ touch here motherland 
  6. then one parameter will turn into several:

     $ echo *her* father here motherland 

about the same thing happened in your case - the *her* parameter of the find program turned into a completely different parameter representing some name (containing the string her ) of a file or directory present in the directory where you ran your command.


additional reading: