adding files to foobar.tar.gz - Unix

This is a discussion on adding files to foobar.tar.gz - Unix ; I have tarred a directory tree with 'tar cf foobar.tar mydirectory' then I have zipped it with 'gzip foobar.tar' creating a file foobar.tar.gz is there a way to add a file titled 'additional.txt' to foobar.tar.gz with one sigle command? yours, ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: adding files to foobar.tar.gz

  1. adding files to foobar.tar.gz

    I have tarred a directory tree with

    'tar cf foobar.tar mydirectory'

    then I have zipped it with

    'gzip foobar.tar' creating a file foobar.tar.gz

    is there a way to add a file titled 'additional.txt' to foobar.tar.gz
    with one sigle command?

    yours,

    John Smith


  2. Re: adding files to foobar.tar.gz

    In article <45b4fd4d$0$24610$9b536df3@news.fv.fi>,
    John Smith wrote:

    > I have tarred a directory tree with
    >
    > 'tar cf foobar.tar mydirectory'
    >
    > then I have zipped it with
    >
    > 'gzip foobar.tar' creating a file foobar.tar.gz
    >
    > is there a way to add a file titled 'additional.txt' to foobar.tar.gz
    > with one sigle command?
    >
    > yours,
    >
    > John Smith


    You may have to put the file into the directory and repeat the archive
    and gzip process or use an inventory file with the -I switch, then
    repeat the process.

    Or you could use star or even GNU tar (in the same directory as gzip)
    with the -z switch:

    gtar -czf foobar.tar.gz mydirectory

    But AFAIK, there's no way to "insert" files into a tarball unzipped or
    not.

    --
    DeeDee, don't press that button! DeeDee! NO! Dee...




  3. Re: adding files to foobar.tar.gz

    2007-01-22, 18:07(+00), John Smith:
    > I have tarred a directory tree with
    >
    > 'tar cf foobar.tar mydirectory'
    >
    > then I have zipped it with
    >
    > 'gzip foobar.tar' creating a file foobar.tar.gz
    >
    > is there a way to add a file titled 'additional.txt' to foobar.tar.gz
    > with one sigle command?

    [...]

    You'll find that this eval command works with zsh:

    eval set =(gunzip < foobar.tar.gz) '
    tar rf $1 additional.txt && gzip < $1 > foobar.tar.gz'

    In anycase, you'll need to gunzip foobar.tar.gz into some temp
    file, do the "tar r" then compress the new file.

    --
    Stéphane

  4. Re: adding files to foobar.tar.gz

    What if I want to add this 'additional.txt' file to gz-archive only (not
    going to mess with existing tarball inside gz-archive) so that when
    decompressed, I would get files 'foobar.tar' and 'additional.txt'. Can that
    be done with one command?


    Yours,

    JS

  5. Re: adding files to foobar.tar.gz

    John Smith writes:

    > What if I want to add this 'additional.txt' file to gz-archive only (not
    > going to mess with existing tarball inside gz-archive) so that when
    > decompressed, I would get files 'foobar.tar' and 'additional.txt'. Can that
    > be done with one command?


    Yes. To do what you want in unix would be to create a new tar file that
    contains the old tar and the new file.

    tar cvfz newfile.tar.gz additional.txt foobar.tar

    or

    tar cvf newfile.tar additional.txt foobar.tar ; gzip newfile.tar


    --
    Todd H.
    http://www.toddh.net/

  6. Re: adding files to foobar.tar.gz

    comphelp@toddh.net (Todd H.) writes:

    > John Smith writes:
    >
    > > What if I want to add this 'additional.txt' file to gz-archive only (not
    > > going to mess with existing tarball inside gz-archive) so that when
    > > decompressed, I would get files 'foobar.tar' and 'additional.txt'. Can that
    > > be done with one command?

    >
    > Yes. To do what you want in unix would be to create a new tar file that
    > contains the old tar and the new file.
    >
    > tar cvfz newfile.tar.gz additional.txt foobar.tar
    >
    > or
    >
    > tar cvf newfile.tar additional.txt foobar.tar ; gzip newfile.tar


    Oh, you said we were starting with a gzipped archive.

    In that case you have 2 options:

    gunzip foobar.tar.gz; tar cvfz newfilt.tar.gz addtional.txt \
    foobar.tar;gzip foobar.tar

    If you wanna do gunzip just once at the end, or as above, just toss
    the .gz in the wrapping tar archive

    tar cvfz newfile.tar.gz additional.txt foobar.tar.gz


    You'll spend more cpu on the front end with option #1 but the
    resulting gzip may have a chance to be a bit smaller with a larger
    compressible dataset to work with. The latter option is quicker
    and uses less peak diskspace.


    --
    Todd H.
    http://www.toddh.net/

  7. Re: adding files to foobar.tar.gz

    On 2007-01-23, John Smith wrote:
    > What if I want to add this 'additional.txt' file to gz-archive only (not
    > going to mess with existing tarball inside gz-archive) so that when
    > decompressed, I would get files 'foobar.tar' and 'additional.txt'. Can that
    > be done with one command?


    No, not with one command. A gzip file is just a compressed file,
    not an archive (IOW it cannot contain more than one file). If you
    want the structure you've outlined, you'll need to nest one tar
    file inside another with additional.txt also in the top-level
    tarball. Another poster has covered that, but it isn't possible
    to have a single command solution.

    --
    Andrew Smallshaw
    andrews@sdf.lonestar.org

  8. Re: adding files to foobar.tar.gz

    At 2007-01-23 03:12PM, "Andrew Smallshaw" wrote:
    > On 2007-01-23, John Smith wrote:
    > > What if I want to add this 'additional.txt' file to gz-archive only (not
    > > going to mess with existing tarball inside gz-archive) so that when
    > > decompressed, I would get files 'foobar.tar' and 'additional.txt'. Can that
    > > be done with one command?

    >
    > No, not with one command. A gzip file is just a compressed file,
    > not an archive (IOW it cannot contain more than one file). If you
    > want the structure you've outlined, you'll need to nest one tar
    > file inside another with additional.txt also in the top-level
    > tarball. Another poster has covered that, but it isn't possible
    > to have a single command solution.


    Unless you use zip:
    zip all.zip foobar.tgz additional.txt

    But that doesn't meet all the requirements outlined above.


    --
    Glenn Jackman
    "You can only be young once. But you can always be immature." -- Dave Barry

+ Reply to Thread