我正在嘗試閱讀特定文件上的內容。我有多個這些文件所在的主機。我在ssh中傳遞下面的命令,以便它可以運行並獲取輸出。通過ssh傳遞find命令的問題
當使用下面的命令時,我得到指定的錯誤。 (其sshed到主機上,但沒有任何反應)
$ ssh host "more $(find /my/path -name "test*")" find: 0652-010 The starting directory is not valid.
當使用EXEC它不工作,(其sshed到主機上,但沒有任何反應)
$ ssh host "find /my/path -name "test*" -exec more {} \;"`
使用時,它正在xargs的預期
$ ssh host "find /my/path -name "test*" | xargs more"
有人能解釋爲什麼方法1 & 2不工作?
請注意,如果我直接在遠程主機上運行命令,每種方法都在工作。例如,以下所有命令在遠程主機中按照預期工作。
more $(find /my/path -name "test*")
find /my/path -name "test*" -exec more {} \;
find /my/path -name "test*" | xargs more
我想找到的文件和閱讀使用更多。方法3也有內部引號,但那個工作,然後爲什麼方法1不起作用?正如你所提到的,我試圖逃避內部報價,但它不起作用。 – user1028948
啊,這是不同的...你看到find返回一個文件列表,而不是文件內容......你可以使用'xargs'來進一步處理(使用)這樣的文件列表,但不能與'_''''''''''''''',因爲你沒有終端。該命令無法決定屏幕的長度,所以停止輸出。相反,它會刷新整個文件,就像「貓」一樣。這又意味着你可以將該輸出傳遞給_local_命令:'ssh host「find/my/path -name \」test * \「| xargs cat」| more' ... – arkascha