Score:3

find /bin -iname 'sh*' doesn't return any result

gg flag

The question is about the syntax of find command

me@222:~$ find /bin -iname 'sh*'

doesn't return any result, while:

me@222:/bin$ find -iname 'sh*'

works fine

setup info: using putty from windows to remote into ubuntu 20 LTS.

Also:
I would like to request for a syntax to properly see exactly what find is doing. for example, the files it is traversing thru, the exact path or filename string it is trying to match against, etc.

terdon avatar
cn flag
For your "also" bit, I think your best bet is to run `set -x` which will at least show you the exact command being run, after the shell has finished expanding things. It wouldn't have helped much in this case though since you're already giving exact paths (the `'*sh'` will be read by `find`, it isn't expanded by the shell).
eliu avatar
gg flag
@terdon sorry, need more info here, are we talking about the "wildcard expansion" behavior of `*`? I have tripped that landmine already, so I am good. However, this `set -x`, I don't see a man page for it, what is it?
terdon avatar
cn flag
See `help set`. It's a bash thing that causes bash to print out the expanded command it will run. So, for example, if you run `find /m* -name foo` it will show `find /media /mnt -name foo`.
Score:11
hr flag

On recent Ubuntu systems, /bin is a symbolic link to /usr/bin as a result of usrmerge, and the find command does not follow symlinks by default. From man find:

   -P     Never follow symbolic links.  This  is  the  default  behaviour.
          When find examines or prints information a file, and the file is
          a symbolic link, the information used shall be  taken  from  the
          properties of the symbolic link itself.

   -L     Follow symbolic links.  [...]

   -H     Do  not  follow symbolic links, except while processing the com‐
          mand line arguments.  When find examines or  prints  information
          about  files, the information used shall be taken from the prop‐
          erties of the symbolic link itself.  The only exception to  this
          behaviour is when a file specified on the command line is a sym‐
          bolic link, and the link can be resolved.  For  that  situation,
          the  information  used is taken from whatever the link points to
          (that is, the link is followed).  The information about the link
          itself  is used as a fallback if the file pointed to by the sym‐
          bolic link cannot be examined.  If -H is in effect  and  one  of
          the  paths specified on the command line is a symbolic link to a
          directory, the contents  of  that  directory  will  be  examined
          (though of course -maxdepth 0 would prevent this).

You probably want

find -H /bin -iname 'sh*'

or

find /usr/bin -iname 'sh*'

to follow the /bin symlink but retain the default behavior below that.

eliu avatar
gg flag
HOLY, VERY very nice catch. thank you. Kinda explains the reason why putting such escoteric information right in the front portion of the man page.
user10489 avatar
in flag
or `find /bin/` to force it to resolve the symlink to its target directory, which does almost the same thing as `-H`
eliu avatar
gg flag
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap03.html#tag_21_03_00_75
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.