The option -C
works; just for clarification I'll post 2 examples:
creation of a tarball without the full path:
full path /home/testuser/workspace/project/application.war
and what we want is just project/application.war
so:
tar -cvf output_filename.tar -C /home/testuser/workspace project
Note: there is a space between workspace
and project
; tar will replace full path with just project
.
extraction of tarball with changing the target path (default to .
, i.e current directory)
tar -xvf output_filename.tar -C /home/deploy/
tar
will extract tarball based on given path and preserving the creation path; in our example the file application.war
will be extracted to /home/deploy/project/application.war
.
/home/deploy
: given on extract
project
: given on creation of tarball
Note : if you want to place the created tarball in a target directory, you just add the target path before tarball name. e.g.:
tar -cvf /path/to/place/output_filename.tar -C /home/testuser/workspace project