I am archiving a folder using following command:
tar jcf "home/username/forum/forum.tar.bz2" /var/www/forum/
Then I am extracting using :
tar jxf forum.tar.bz2 ./
It extracts correctly, but creates /home/username/forum/var/www/forum
folder. What do I need to do in order to extract it into /home/username/forum
folder?
Thank you
In addition to dv3500ea's answer, you can use the next command to extract tarballs containing
var/www/forum/
toforum/
:var/
andwww/
are two path components, hence the2
in--strip-components
.If you're not sure what's inside a tarball, use the
t
option:Pipe it through
less
so you an use arrow keys for scrolling.A general note about the options used:
x
- extracts a tarball, I always place it as first option since it's most logical to see what a command doesc
- creates a tarballt
- lists the contents of a tarballj
- make tar uncompress bzip2 compressed tarballs. This is redundant with the.bz2
extension, so you may remove this option as wellf
- this option expects a filename as argument, it's either the tarball to be extracted (tar xf file.tar.bz2
) or created (tar cf file.tar.bz2
)When creating the archive use
-C /var/www/
to change the current directory to /var/www while creating the archive.This will cause the 'forum' folder to be in the top level of the archive and will therefore extract directly into the current folder when you run:
The fast (and possibly wrong) solution would be to change your command to change directories before tarring. IE: