python - 管道符和ssh傳文件
問題描述
看到可以用一條命令傳輸文件
gzip -c aa.txt | ssh root@192.168.1.1 ' gunzip -c - > /home/bb.txt'
請問這條命令怎么理解?還有,發(fā)現(xiàn)對文件夾進(jìn)行這樣的操作會(huì)失敗,有什么辦法傳輸文件夾么?求指教
問題解答
回答1:命令參數(shù)解釋: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>.
不知道鬧哪樣,兩條命令的幫助文檔是一樣的,開發(fā)者偷懶了
也就是說 -c 不壓縮文件,而是直接輸出到標(biāo)準(zhǔn)輸出。
gunzip -,不是從文件接收壓縮文件,而是從標(biāo)準(zhǔn)輸入接收。
|:管道>:重定向
整條命令分析gzip -c aa.txt | ssh root@192.168.1.1 'gunzip -c - > /home/bb.txt'
gzip -c aa.txt:壓縮aa.txt文件,并將壓縮后的結(jié)果輸出到標(biāo)準(zhǔn)輸出
ssh root@192.168.1.1 '命令':在遠(yuǎn)程機(jī)器上執(zhí)行命令
命令gunzip -c -:解壓文件,原壓縮文件是由標(biāo)準(zhǔn)輸入傳入的,輸出結(jié)果直接輸出到標(biāo)準(zhǔn)輸出
> /home/bb.txt:將標(biāo)準(zhǔn)輸出重定向到文件/home/bb.txt
對文件夾進(jìn)行這樣的操作會(huì)失敗gzip不支持對目錄操作
回答2:你要么完全換用netcat來收發(fā)。要么,本地tar壓縮一下,對端解壓縮。
回答3:管道是將前一個(gè)命令輸出作為輸入。 也可以先壓縮成一個(gè)臨時(shí)文件,再用scp
相關(guān)文章:
1. mysql - 面試題:如何把login_log表轉(zhuǎn)換成last_login表?2. html5 - iphone5手機(jī),微信中無法打開優(yōu)酷鏈接?3. javascript - 為什么嵌套的Promise不能按預(yù)期捕獲Exception?4. javascript - nodejs實(shí)現(xiàn)異步時(shí)遇到的一個(gè)問題5. 剛放到服務(wù)器的項(xiàng)目出現(xiàn)這中錯(cuò)誤,有高手指點(diǎn)嗎6. apache - 想把之前寫的單機(jī)版 windows 軟件改成網(wǎng)絡(luò)版,讓每個(gè)用戶可以注冊并登錄。類似 qq 的登陸,怎么架設(shè)服務(wù)器呢?7. javascript - 編程,算法的問題8. css3 - Typecho 后臺(tái)部分表單按鈕在 Chrome 下出現(xiàn)靈異動(dòng)畫問題,求解決9. python 操作mysql如何經(jīng)量防止自己的程序在之后被惡意注入(說白了就是問一下python防注入的一些要點(diǎn))10. css - 手機(jī)qq打開網(wǎng)頁無法使用文件上傳功能?
