How do I create a tar archive that will not expand to a subfolder?
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
加载中,请稍侯......
精彩评论