linux - 从管道在命令行上创建 zip 时,如何在 zip 中指定文件名?

标签 linux zip stdin pipe

我正在尝试从管道输入的文件内容创建一个 zip 文件,例如

mysql [params and query] | zip -q output.zip -

这会正确写入 zip,但是当您打开 zip 时,其中的文件名为“-”。有没有什么方法可以指定 zip 中传输数据的文件名?

最佳答案

你可以做到这一点。

ls | zip test.zip -@

这是根据我在目录中有 3 个文件的想法完成的。

-rw-rw-r-- 1 xxx domain users   6 Jan  7 11:41 test1.txt
-rw-rw-r-- 1 xxx domain users   6 Jan  7 11:41 test2.txt
-rw-rw-r-- 1 xxx domain users   6 Jan  7 11:41 test3.txt

和文件本身,结果就是

Archive:  test.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
        6  01-07-10 11:41   test1.txt
        6  01-07-10 11:41   test2.txt
        6  01-07-10 11:41   test3.txt
 --------                   -------
       18                   3 files

来自 Linux Zip 手册页

If the file list is specified as -@, zip takes the list of input files from standard input.

关于linux - 从管道在命令行上创建 zip 时,如何在 zip 中指定文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2019603/

相关文章:

git - 防止 PowerShell "boxing"程序输出

TCL - 将 STDIN 提供给执行程序

c - 将已删除的文件重新附加到目录

haskell - 如何使用 zip 和列表理解来定义 zipWith

python-2.7 - 你能在 python 2 中为 zip() 函数动态创建参数吗?

c - 使用键盘作为标准输入

linux - 过滤 Bash session 中的所有输出

linux - 运行 var 中存储的命令时出现 Bash 错误 "command not found"

java - Elasticsearch:不支持的 major.minor 版本 52.0

zip - 如何从命令行创建文件以测试 Zip Slip 漏洞