سؤال

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top