创建tar归档文件时添加目录 [英] add a directory when creating tar archive

查看:75
本文介绍了创建tar归档文件时添加目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想压缩某些文件(和目录),但想创建这些文件应驻留的其他目录.

I want to tar some files (and directories) but want to create an additional directory those files should reside in.

例如,以下目录结构:

myproject
  + file1
  + file2
  + subdir1
    + file3

我进入 myproject 目录,并想要创建tar归档文件

I cd into the myproject directory and want to create the tar archive

tar czf myproject.tgz --place-into-dir myproject-1.0 file2 subdir1

接收具有以下内容的tar归档文件:

to receive a tar archive with the following content:

myproject-1.0
  + file2
  + subdir1
    + file3

我正在搜索类似我上面虚构的"--place-into-dir"的选项.因此,不应将文件直接放置在存档中,而应放置在仅在tar存档中创建的其他目录中.

I am searching for an option like my fictional "--place-into-dir" above. So the files should not be placed directly into the archive, but instead into an additional directory that is only created in the tar archive.

我要避免先创建该目录,然后将所有文件复制到该目录,然后再次删除它们以创建tar存档.

I want to avoid first creating that directory, copying all the files to that directory and then deleting them again only to create the tar archive.

推荐答案

您可以使用-transform :

tar czf myproject.tgz --transform 's,^,myproject-1.0/,' file2 subdir1

这篇关于创建tar归档文件时添加目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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