Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
hi there i just wanted to ask is there a way to append files or folders into an already existing tar.bz2 archive? i am writing a script that after its ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    35

    tar.bz2 compression


    hi there

    i just wanted to ask is there a way to append files or folders into an already existing tar.bz2 archive?

    i am writing a script that after its done doing it job, it compresses the acquired files into one tar.bz2 archive, i tired tar -jrf but for some reason i always end up getting this error
    "tar: Cannot update compressed archives"

    thanks

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,664
    AFAIK, the answer to that is no. That said, there might be some special tools that would expand the archive in memory and allow you to add files which it could then re-tar and re-compress the archive. I just don't know what they might be, if they exist. For read-only operations, most Linux GUI file browsers such as Konqueror can expand and read bzip2 tar archives without problems, but they cannot add a file to them.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Newbie
    Join Date
    Sep 2004
    Location
    UK
    Posts
    161
    Don't think you can do that. The compressed tar is a tar ball which is then compressed whereas a zip file is a collection of files that have been individually compressed. I think you will have to uncompress that tgz amd then append the files and then recompress it.
    In a world without walls and fences, who needs Windows and Gates?

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    May 2009
    Posts
    35
    k, fair enough

    one last simple question, is there a way to redirect a file into a compressed one

    for example instead of writing

    vmstat 5 13 > stat
    tar -rf archive.tar stat

    is there a way to immediately redirect vmstat into and archive.tar with the name stat??

  6. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,664
    You could do something like this (maybe - I haven't tried it yet):
    Code:
    tar -rf archive.tar `vmstat 5 13 >stat ; echo stat`
    Alternatively, you could create a script to do it.

    ---- A Little Later ----

    Ok. I tried the technique shown above, and it works just fine on my CentOS 5.3 system.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #6
    Just Joined!
    Join Date
    May 2009
    Posts
    35
    Quote Originally Posted by Rubberman View Post
    You could do something like this (maybe - I haven't tried it yet):
    Code:
    tar -rf archive.tar `vmstat 5 13 >stat ; echo stat`
    Alternatively, you could create a script to do it.

    ---- A Little Later ----

    Ok. I tried the technique shown above, and it works just fine on my CentOS 5.3 system.
    this is not what i meant m8, i meant to ask if there is a way to archive smth from the get go without first saving it, your above script first saves stat into the current dictionary then compresses it, so that after its done we would have one stat file and one archived file.

    is there a way to only have one archived file at the end of the process??

    p.s: english is not the my first language, so if u didnt understand me i will repeat the question or smth

  8. #7
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by a_n_h View Post
    this is not what i meant m8, i meant to ask if there is a way to archive smth from the get go without first saving it, your above script first saves stat into the current dictionary then compresses it, so that after its done we would have one stat file and one archived file.

    is there a way to only have one archived file at the end of the process??

    p.s: english is not the my first language, so if u didnt understand me i will repeat the question or smth
    I am afraid that there's no straight way to do what you ask for. You could use a named pipe, which is nothing but a file that acts like a FIFO (check mkfifo), with that you can pass a data stream from one point to another. The problem is that tar can only store files with a name. You can't simply throw contents inside a tar file. It wouldn't be able to restore it to a file afterwards anyway.

    You can create a temporal file in /dev/shm or /tmp though.

  9. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,664
    Quote Originally Posted by a_n_h View Post
    this is not what i meant m8, i meant to ask if there is a way to archive smth from the get go without first saving it, your above script first saves stat into the current dictionary then compresses it, so that after its done we would have one stat file and one archived file.

    is there a way to only have one archived file at the end of the process??

    p.s: english is not the my first language, so if u didnt understand me i will repeat the question or smth
    Tar only works on files. You could do this (again, haven't tried it yet):
    Code:
    tar -rf archive.tar `vmstat 5 13 >stat ; echo stat` ; rm stat
    At least it would remove the temporary file 'stat' after it has been archived, leaving you with just the archive.tar file.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  10. #9
    Just Joined!
    Join Date
    May 2009
    Posts
    35
    Quote Originally Posted by Rubberman View Post
    Tar only works on files. You could do this (again, haven't tried it yet):
    Code:
    tar -rf archive.tar `vmstat 5 13 >stat ; echo stat` ; rm stat
    At least it would remove the temporary file 'stat' after it has been archived, leaving you with just the archive.tar file.
    yea this is what i am currently doing, i just thought there is more a direct approach for it, oh well

    thanks for the help guys

  11. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,664
    Like I said, sometimes a script is the proper solution. One that takes a couple of arguments, such as the name of the archive.tar file and the number of iterations to vmstat so you can tailor it to your needs (the defaults can be the same values you use now) at runtime. That approach eliminates typos for the most part.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •