我想使用压缩stdin的内容zip,例如:
echo 'foo bar' | zip > file.zip
Run Code Online (Sandbox Code Playgroud)
这工作正常,但解压缩时,未压缩的文件名是 -
我想知道如何为stdin指定文件名?
pol*_*zul 10
使用 fifo(命名管道)而不是直接通过管道传输 stdin!
mkfifo text.txt # create fifo
echo 'foo bar' > text.txt & # pipe data to fifo, in background
zip --fifo file.zip text.txt # note the `--fifo` argument to zip
rm text.txt # cleanup
Run Code Online (Sandbox Code Playgroud)
结果:
$ unzip -l file.zip
Archive: file.zip
Length Date Time Name
--------- ---------- ----- ----
8 2020-11-29 12:30 text.txt
--------- -------
8 1 file
Run Code Online (Sandbox Code Playgroud)
请注意,fifo 是一个命名管道。就像著名的匿名管道一样,|硬盘上不会存储任何数据,而是直接从写入器传输到读取器。
您可以做的是正常通过管道传输文件,然后在 zip 中重命名
echo 'foo bar' | zip > file.zip
printf "@ -\n@=filename.txt\n" | zipnote -w file.zip
Run Code Online (Sandbox Code Playgroud)
小智 -8
echo 'foo bar' | zip -@ /path/to/zipfile.zip应该在保持文件名完整性的同时执行此操作
| 归档时间: |
|
| 查看次数: |
8387 次 |
| 最近记录: |