开发者

How do I create a tar archive that will not expand to a subfolder?

开发者 https://www.devze.com 2023-04-13 05:33 出处:网络
I don\'t want to create a \"flat\" tarball that has no internal directory structure. But I want the top-level files to be \"loose\" rather than mirroring the directory structure they were on originall

I don't want to create a "flat" tarball that has no internal directory structure. But I want the top-level files to be "loose" rather than mirroring the directory structure they were on originally.

Consider:

+ archives
|
+ data
    |
    + site
        |
        + file1.html
        |
        + subdirectory
               |
               + etc...

If I cd into archives and create my tar there, eg: tar -czf archive.tgz ../data/site/* when I extract the tarball later it will recreate data/site/... and then I'll have 开发者_运维百科to mv data/site/* ../some/other/dir.

I'd like to be able to just tar -xzf archive.tgz -C ../some/other/dir and have eg file1.html be right there inside ../some/other/dir.


Instead of cding to archives and running tar there with a path to the tarfile contents, you should cd to where the contents are and specify a path to the tarfile you're creating:

cd data/site
tar -czf ../../archives/archive.tgz *


You can also use the option tar -czf archive.tgz --directory=data/site/ . without going to the folder

0

精彩评论

暂无评论...
验证码 换一张
取 消