LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to create tar and compress at the same time (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-tar-and-compress-at-the-same-time-936736/)

sam_nyc 03-27-2012 01:20 PM

how to create tar and compress at the same time
 
Hi,

I always create the tar then I compress it, as a two steps. How can I do this in one step?

Code:

xyz - is a directory which is under /var/log

Step 1. tar -cvf /home/sam/march27_backup.tar /var/log/xyz
Step 2. gunzip march27_backup.tar

I did this and I get error message.

Code:

tar -cvf /home/sam/march27_backup.tar /var/log/xyz |gzip -c
Thank you.

druuna 03-27-2012 01:28 PM

Hi,

Tar's -z (--gzip) option can do that:
Code:

tar -zcvf /home/sam/march27_backup.tgz /var/log/xyz
BTW: The -j (--bzip2) can be used to use bzip2. There are more:
Code:

tar --help
too see all options.

Hope this helps.

TobiSGD 03-27-2012 01:32 PM

tar can handle the compression itself (using external programs). Have a look at the options -j, -z and -Z in the man page, they work for creating and extracting archives (although not necessary for extracting, tar recognizes compression automatically in that case).

sam_nyc 03-27-2012 01:42 PM

Thank you so much for the quick answer.

druuna 03-27-2012 01:51 PM

You're welcome :)

BTW: Can you put up the [SOLVED] tag.
first post -> Thread Tools -> Mark this thread as solved


All times are GMT -5. The time now is 12:59 AM.