LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   About tar command (https://www.linuxquestions.org/questions/linux-newbie-8/about-tar-command-512473/)

satimis 12-21-2006 02:22 AM

About tar command
 
Hi folks,

I have been looking around on man tar and can't resolve what option shall be up on running;

tar jcpf tarball.tar.bz2 /path/to/tar/

to exclude the directories '/path' and 'to' on the compressed tarball only retaining '/tar directory.

Please advise. TIA


B.R.
satimis

Nathanael 12-21-2006 02:41 AM

it will not include contents of /path and /path/to, but will keep the relative path of tar. as you are telling tar with /path/to/tar to make an archive of that folder it will keep the that info to know where to extract the folder tar to.
if you only want the archive to hold ./tar then do
cd /path/to
tar jcpf /path/to/archive/tarball.tar.bz2 tar

Simon Bridge 12-21-2006 02:51 AM

...from the tar manpage:
Code:

tar -cvvf foo.tar foo/
              tar contents of folder foo in foo.tar

so: tar -cvvf bar.tar foo/bar/ will tar the content of the bar folder
... but tar -cvvf foo.tar foo/bar (i.e. leave off the trailing "/")should give you the bar folder itself, as well. (Directories are files too.)

You have tried this of course...

satimis 12-21-2006 02:58 AM

Hi Nathanael,

Tks for your advice.

Quote:

it will not include contents of /path and /path/to, but will keep the relative path of tar. as you are telling tar with /path/to/tar to make an archive of that folder it will keep the that info to know where to extract the folder tar to.
if you only want the archive to hold ./tar then do
cd /path/to
tar jcpf /path/to/archive/tarball.tar.bz2 tar
I don't want to retain the complete path after decompresing;

/path/to/tar/

After decompression I expect only to have;

/tar

Neither I need to compress the contents on /path and /path/to/

Can I hold the compressed tarball on another directory instead of on /path/to/tar/

Tks.


B.R.
satimis

Nathanael 12-21-2006 05:19 AM

if you had read what i wrote you would have seen that the last 2 lines of my post address exactly what you need to do to archieve that!!!

cd to the parent directory
and with /path/to/archive/tarball.tar.bz2 you specify where you want you archive to be saved - ie replace /path/to/archive with /root and you will find a file tarball.tar.bz2 in /root!!!!!

by cd'ing into the parent directory (cd /path/to ) and then taring ./tar you will also only have a record for ./tar in your archive and not ./path/to/tar...

give it a shot and see what it does!!


All times are GMT -5. The time now is 03:42 AM.