3

This command with a * in the find path works fine on the local server

Svr1$ find /path/*/foo/ -name "*20160208"

When I try this remotely from another server it doesn't work

Svr2$ ssh Svr1 find '/path/*/foo/' -name "*20160208*"

The error message is:

find: stat() error /path/*/foo/: No such file or directory

However, if I change the search path to avoid using the * it works fine. Like this:

Svr2$ ssh Svr1 find '/path/' -name "*20160208*"

Any idea what I'm doing wrong?

Many thanks.

LLJ
  • 35

2 Answers2

4

Your problem is that the find command does not interpolate/interpret directory glob(s) (the directory list that it must seek under), it only interpolates the pattern as a glob that must match. What interprets the directory globs is the shell itself you run find inside. When you run find via ssh, there is no shell to do this job.

Luckily enough, there's no rule against running a shell via ssh and make that shell run your command with all the required stuff interpolated and the rest of the wildcards preserved for find itself.

Something like what I used on my machine:

ssh lx@localhost "bash -c '/usr/bin/find /tmp/d* -name \"f*\" '"
lx@localhost's password:
/tmp/d1/f1
/tmp/d2/f2
user556625
  • 4,400
0

The way you write it is evaluated on the local host, which is usually something you don't want. You need to escape the sequences to let it evaluate on the other host. Something like this should do that:

Svr2$ ssh Svr1 "find /path/*/foo/ -name \"*20160208*\""
Jakuje
  • 10,827