linux - 完成从 tarball 中提取给定文件后,管道 un-tar kill pipe

标签 linux bash curl pipe tar

我正在使用 curl 下载一个大压缩包。我只对那个 tarball 中的一个文件感兴趣。所以目前我正在将 curl 的输出通过管道传输到 tar。

$ curl -S http://url/of/big/tarball.tar.gz | tar -xv path/of/one/file

尽管这样效果很好。即使所需的文件已经解压,它仍然会完全下载巨大的 tarball。有没有办法在 tar 完成提取所需文件时自动中断它?

编辑:对于在网上游荡的任何人来说都是同样的问题。我最终创建了一个小的 bash 脚本

trap 'kill $(jobs -p)' EXIT
curl -S "${URL}" | tar -C "${OUTPUT_DIR}" -xv "${FILES[@]}" 2>&1 | head -"${FILES_CNT}" > "${CTRL_FILE}" 2>&1 &
 # Wait for the required files to be found in the tar
until [[ -s "${CTRL_FILE}" && $(wc -l "${CTRL_FILE}" | cut -d' ' -f 8) -ge "${FILES_CNT}" ]]; do
    sleep 10s
done

最佳答案

trap 'kill $(jobs -p)' EXIT
curl -S "${URL}" | tar -C "${OUTPUT_DIR}" -xv "${FILES[@]}" 2>&1 | head -"${FILES_CNT}" > "${CTRL_FILE}" 2>&1 &
# Wait for the required files to be found in the tar
until [[ -s "${CTRL_FILE}" && $(wc -l "${CTRL_FILE}" | cut -d' ' -f 8) -ge "${FILES_CNT}" ]]; do
    sleep 10s
done

关于linux - 完成从 tarball 中提取给定文件后,管道 un-tar kill pipe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48673056/

相关文章:

c - 如何在linux上写命令

c - 重定向标准输入 - C

c - 如何使用 grep 或 find 查找函数的定义或类名?

linux - wmctrl:移动全屏窗口

bash - 重命名与目录名称同名的文件

post - 使用 Curl 和 Postman 构建 HTTP POST 请求

linux - 如何在 bash 中对逗号分隔值进行排序?

linux - 删除文件末尾的一系列字符,包括 LF(换行符)

rest - 在 2.6.1(非专业版)中使用 Artifactory REST API 和curl

php - 如何使用 CURL 而不是 file_get_contents?