Answers:
您只错过了一个符号=)
ssh user@socket command < /path/to/file/on/local/machine
scp
。
/dev/stdin
或-
。可能会或可能不会工作(/dev/stdin
是一个文件,但寻找它会失败)
无论命令如何,一种有效的方法是通过远程文件系统使文件在远程计算机上可用。由于您具有SSH连接:
# What if remote command can only take a file argument and not read from stdin? (1_CR)
ssh user@socket command < /path/to/file/on/local/machine
...
cat test.file | ssh user@machine 'bash -c "wc -l <(cat -)"' # 1_CR
作为bash
进程替换<(cat -)
或< <(xargs -0 -n 1000 cat)
(请参见下文)的替代方法,您可以仅使用xargs
并将cat
指定文件的内容通过管道传输到wc -l
(更便于移植)。
# Assuming that test.file contains file paths each delimited by an ASCII NUL character \0
# and that we are to count all those lines in all those files (provided by test.file).
#find . -type f -print0 > test.file
# test with repeated line count of ~/.bash_history file
for n in {1..1000}; do printf '%s\000' "${HOME}/.bash_history"; done > test.file
# xargs & cat
ssh localhost 'export LC_ALL=C; xargs -0 -n 1000 cat | wc -l' <test.file
# Bash process substitution
cat test.file | ssh localhost 'bash -c "export LC_ALL=C; wc -l < <(xargs -0 -n 1000 cat)"'