简体   繁体   English

如何在没有父目录但最后一个目录的情况下进行tar

[英]how to tar without the parent directory but with the last directory

I am trying to tar a directory without the parent directories and I have found a solution so far which removes the parent directories and tar all the files under a directory called (DIR) to a DIR.tar.gz file using the following: 我正在尝试将没有父目录的目录压缩为tar,到目前为止,我已经找到了一种解决方案,该解决方案使用以下方法将父目录删除,并将目录(DIR)下的所有文件压缩为DIR.tar.gz文件:

tar -cvzf $DIR.tar.gz -C $path/$DIR .

But if I want to untar the tared file, it will untar all the files in the current directory, however, I want to be able to tar the dir in a way which when I use tar -xzvf, it will untar it into folder called DIR. 但是,如果我想解压缩被解压缩的文件,它将解压缩当前目录中的所有文件,但是,我希望能够以某种方式对目录进行解压缩,当我使用tar -xzvf时,它将解压缩到名为的文件夹中DIR。 IT should be simple, but I am not able to find the solution on the net. IT应该很简单,但是我无法在网上找到解决方案。 Any hint? 有什么提示吗?

I believe what you want is: 我相信您想要的是:

tar -cvzf $DIR.tar.gz -C $path ./$DIR

This should change the directory to your folder path (-C) and only include the relative directory ($DIR) that you're trying to archive. 这应该将目录更改为文件夹路径(-C),并且仅包含您要存档的相对目录($ DIR)。

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

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