python - 管道符和ssh传文件
问题描述
看到可以用一条命令传输文件
gzip -c aa.txt | ssh root@192.168.1.1 ' gunzip -c - > /home/bb.txt'
请问这条命令怎么理解?还有,发现对文件夹进行这样的操作会失败,有什么办法传输文件夹么?求指教
问题解答
回答1:命令参数解释:gzip -h
Usage: gzip [OPTION]... [FILE]...Compress or uncompress FILEs (by default, compress FILES in-place).Mandatory arguments to long options are mandatory for short options too. -c, --stdout write on standard output, keep original files unchanged -d, --decompress decompress -f, --force force overwrite of output file and compress links -h, --helpgive this help -l, --listlist compressed file contents -L, --license display software license -n, --no-name do not save or restore the original name and time stamp -N, --namesave or restore the original name and time stamp -q, --quiet suppress all warnings -r, --recursive operate recursively on directories -S, --suffix=SUF use suffix SUF on compressed files -t, --testtest compressed file integrity -v, --verbose verbose mode -V, --version display version number -1, --fastcompress faster -9, --bestcompress better --rsyncable Make rsync-friendly archiveWith no FILE, or when FILE is -, read standard input.
gunzip -h
Usage: gzip [OPTION]... [FILE]...Compress or uncompress FILEs (by default, compress FILES in-place).Mandatory arguments to long options are mandatory for short options too. -c, --stdout write on standard output, keep original files unchanged -d, --decompress decompress -f, --force force overwrite of output file and compress links -h, --helpgive this help -l, --listlist compressed file contents -L, --license display software license -n, --no-name do not save or restore the original name and time stamp -N, --namesave or restore the original name and time stamp -q, --quiet suppress all warnings -r, --recursive operate recursively on directories -S, --suffix=SUF use suffix SUF on compressed files -t, --testtest compressed file integrity -v, --verbose verbose mode -V, --version display version number -1, --fastcompress faster -9, --bestcompress better --rsyncable Make rsync-friendly archiveWith no FILE, or when FILE is -, read standard input.Report bugs to <bug-gzip@gnu.org>.
不知道闹哪样,两条命令的帮助文档是一样的,开发者偷懒了
也就是说 -c 不压缩文件,而是直接输出到标准输出。
gunzip -,不是从文件接收压缩文件,而是从标准输入接收。
|:管道>:重定向
整条命令分析gzip -c aa.txt | ssh root@192.168.1.1 'gunzip -c - > /home/bb.txt'
gzip -c aa.txt:压缩aa.txt文件,并将压缩后的结果输出到标准输出
ssh root@192.168.1.1 '命令':在远程机器上执行命令
命令gunzip -c -:解压文件,原压缩文件是由标准输入传入的,输出结果直接输出到标准输出
> /home/bb.txt:将标准输出重定向到文件/home/bb.txt
对文件夹进行这样的操作会失败gzip不支持对目录操作
回答2:你要么完全换用netcat来收发。要么,本地tar压缩一下,对端解压缩。
回答3:管道是将前一个命令输出作为输入。 也可以先压缩成一个临时文件,再用scp
相关文章:
1. javascript - npm下载的模块不完整是什么问题?2. java - Spring事务回滚问题3. css - 手机qq打开网页无法使用文件上传功能?4. javascript - 单个页面执行多个jsonp的ajax请求,如何判断一个ajax请求执行完毕执行再另一个?5. node.js - 我想让最后进入数据库的数据,在前台最先展示,如何做到?6. apache - 想把之前写的单机版 windows 软件改成网络版,让每个用户可以注册并登录。类似 qq 的登陆,怎么架设服务器呢?7. 刚放到服务器的项目出现这中错误,有高手指点吗8. javascript - JS设置Video视频对象的currentTime时出现了问题,IE,Edge,火狐,都可以设置,反而chrom却...9. python 操作mysql如何经量防止自己的程序在之后被恶意注入(说白了就是问一下python防注入的一些要点)10. mysql - 面试题:如何把login_log表转换成last_login表?
