繁体   English   中英

如何将单个文件压缩为 tar.gz

[英]how to compress single file to tar.gz

我正在尝试压缩单个文件

所需的 output ==> myfile.tar.gz ==> myfile.tar ==> myfile.bin

我运行的命令...

subprocess.call(['tar', '-zcvf', '/path/to/desitnation/myfile.tar.gz', "./path/to/file/myfile.bin"]

我得到的 output 是

myfile.tar.gz ==> myfile.tar ==> ./path/to/file/myfile.bin

tar有一个-C ( --directory ) 选项,可以在开始处理文件之前更改目录:

subprocess.call(['tar',
  '-C', '/path/to/file/',
  '-zcvf',
  '/path/to/destination/myfile.tar.gz', "myfile.bin"])

有关详细信息,请参阅tar手册页


您可以使用subprocess.callcwd参数来完成同样的事情:

subprocess.call(['tar',
  '-zcvf',
  '/path/to/destination/myfile.tar.gz', "myfile.bin"], 
  cwd='/path/to/file')

有关详细信息,请参阅子流程文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM