在 Ubunutu 16 上将 tar 创建到 stdout [英] Create tar into stdout on Ubunutu 16

查看:36
本文介绍了在 Ubunutu 16 上将 tar 创建到 stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tar 无法写入 Ubuntu 16 上的标准输出:

tar cannot write to standard output on Ubuntu 16:

prod ~    $ cat /etc/os-release  | grep -i version
VERSION="16.04.2 LTS (Xenial Xerus)"
VERSION_ID="16.04"
VERSION_CODENAME=xenial

prod ~    $ tar -cf - tmp
tar: Refusing to write archive contents to terminal (missing -f option?)
tar: Error is not recoverable: exiting now

让我们在 CentOS7 上试试:

Let's try on CentOS7:

[root@drft068 ~]# tar -cf - /tmp
tar: Removing leading `/' from member names
tar: /tmp/mongodb-27018.sock: socket ignored
tar: /tmp/mongodb-27017.sock: socket ignored
tmp/00017770000000000000000000000000131574472010

我做错了什么?

推荐答案

为了在这里有一个正确的 SO 答案,我浓缩了 @Kamajii 和 @Cyrus 对问题的评论(请考虑自己这样做......).

To have a proper SO answer here, I condensed @Kamajii and @Cyrus comments to the questions (please consider doing that yourselves ...).

tar 注意到 stdout 将在终端上结束.除了输出是二进制的,因此对于人类来说并不是真正可读的,它也是一个 安全风险.

tar notices that stdout will end up on a terminal. Besides the output is binary and thus not really readable for humans it is also a security risk.

只要您重定向 tar 进程的标准输出,它就会起作用.给出的一个例子涉及 cat,它不关心你是否给它一个二进制 blob.于是

As soon as you redirect stdout of the tar process, it will work. One example given involves cat, which doesnt care if you give it a binary blob. Thus

<代码>tar -cf - tmp |猫

将显示二进制内容.否则 tar -cf - tmp >mytmp.tar 可能比您想要使用的更接近(尽管对于此示例,tar -cf mytmp.tar tmp 将是典型的调用).

will display the binary stuff. Otherwise tar -cf - tmp > mytmp.tar is probably closer than what you want to use (although for this example a tar -cf mytmp.tar tmp would have been the typical call).

这篇关于在 Ubunutu 16 上将 tar 创建到 stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆