LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-27-2012, 02:20 PM   #1
sam_nyc
Member
 
Registered: Aug 2009
Posts: 41

Rep: Reputation: 1
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.
 
Old 03-27-2012, 02:28 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
1 members found this post helpful.
Old 03-27-2012, 02:32 PM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
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).
 
Old 03-27-2012, 02:42 PM   #4
sam_nyc
Member
 
Registered: Aug 2009
Posts: 41

Original Poster
Rep: Reputation: 1
Smile

Thank you so much for the quick answer.
 
Old 03-27-2012, 02:51 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] compress with tar without saving full paths razor7 Linux - Newbie 6 11-14-2016 05:57 AM
[SOLVED] tar (compress) specific files ted_chou12 Linux - Newbie 3 12-01-2011 07:42 AM
tar with parameter -T (or --files-from) does not compress? Babelduo Linux - Server 3 01-18-2011 09:23 AM
Resize (*.jpg) -> Rename -> Compress (xyz.tar) ? control_guy Linux - Newbie 6 05-22-2008 02:34 PM
compress a directory using tar muskiediver Linux - General 4 07-18-2006 11:24 AM


All times are GMT -5. The time now is 10:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration