Unix обнаружил, что не работает с подстановочными символами в пути, когда ssh'ing

923
LLJ

Эта команда с * в пути поиска отлично работает на локальном сервере

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

Когда я пытаюсь это удаленно с другого сервера, это не работает

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

Сообщение об ошибке:

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

Однако, если я изменю путь поиска, чтобы избежать использования *, он будет работать нормально. Как это:

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

Есть идеи, что я делаю не так?

Большое спасибо.

2
звезда в кавычках делает это буквальным barlop 8 лет назад 0
что если вы измените `'/ path / * / foo /'` на `/ path / * / foo /`? barlop 8 лет назад 0
На самом деле, так было у меня изначально, и это не сработало. Я задал вопрос здесь, и мне сказали поставить путь в кавычках. Это все еще не работает, и у меня нет идей. LLJ 8 лет назад 0

2 ответа на вопрос

3
Gombai Sándor

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 
0
Jakuje

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*\""