所以这是我已经做的:
我有一个名为 abc.txt 的文件,其中包含文件列表。我正在使用 abc.txt 将这些文件移动到一个文件夹,tar 那个文件夹,最后我从运行 GNU/Linux 的服务器将 tar 下载到我的本地 PC。
以下是列表形式的步骤:
如果 abc.txt 包含 2 个文件,例如:
example1.css
example2.css
Run Code Online (Sandbox Code Playgroud)
我需要分别从 abc.txt 下载这些文件并直接下载到本地 PC。
由于 ftp 或 sftp 需要文件名来下载它,我如何从 abc.txt 中读取它?
如果文件abc.txt
包含相对于 的文件名列表/path/to/base
:
ssh user@server tar c -T /path/to/abc.txt -C /path/to/base | (cd /tmp; tar xv)
Run Code Online (Sandbox Code Playgroud)
这会即时创建一个 tarball,而无需实际将其保存在任何地方,将其通过管道传输到本地 shell,提取,有效地复制列出的文件。
额外提示
如果文件abc.txt
包含绝对路径列表:
ssh user@server tar c -T /path/to/abc.txt | (cd /tmp; tar xv)
Run Code Online (Sandbox Code Playgroud)
如果文件abc.txt
在您的本地系统上,而不是在远程系统上:
ssh user@server tar c -T- < /path/to/abc.txt | (cd /tmp; tar xv)
Run Code Online (Sandbox Code Playgroud)
要使用gzip
压缩(使用默认级别 6):
ssh -C user@server tar c -T /path/to/abc.txt | (cd /tmp; tar xv)
Run Code Online (Sandbox Code Playgroud)
要使用gzip
压缩级别 9:
ssh user@server 'tar c -T /path/to/abc.txt | gzip -9' | (cd /tmp; tar zxv)
Run Code Online (Sandbox Code Playgroud)