How to create .tgz file without creating .tar file? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

How to create .tgz file without creating .tar file?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-22-2012
Pawan Kumar Pawan Kumar is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 11 March 2013, 1:13 AM EDT
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Bug How to create .tgz file without creating .tar file?

Hi,

Could anyone help me in providing command to generate .tgz file without creating .tar file?

currently i am using below command for doing the same but if tar file has big size and there is no space in drive then tgz file will not be generated. I want to generate tgz file directly without generating tar file.

Code:
tar -cvf $Location/$ZIPFILE.tar /mnt/*.*

and later, it compresses it and removes the tar:

Code:
gzip $Location/$ZIPFILE.tar
rm -rf $Location/$ZIPFILE.tar

WBR,
-Pawan

Last edited by Franklin52; 10-23-2012 at 05:28 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 10-22-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 September 2014, 5:50 PM EDT
Location: Saskatchewan
Posts: 19,366
Thanks: 787
Thanked 3,258 Times in 3,054 Posts
Two ways:


Code:
# direct way, works on most systems
tar -zcf /path/to/file.tar.gz files I want to be inside the tar
# indirect way, may be necessary on some systems
tar -cf - files I want to be inside the tar | gzip > /path/to/file.tar.gz

The Following User Says Thank You to Corona688 For This Useful Post:
Pawan Kumar (10-22-2012)
Sponsored Links
    #3  
Old 10-22-2012
Pawan Kumar Pawan Kumar is offline
Registered User
 
Join Date: Oct 2012
Last Activity: 11 March 2013, 1:13 AM EDT
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
tar -pczf MyBackup.tar.gz <file which needs to be inside>

will above command standard?

I have only concern is that wthether the above command generates tar file temporarily then delete afterwards? or it not at all generates tar file?
    #4  
Old 10-23-2012
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 September 2014, 5:50 PM EDT
Location: Saskatchewan
Posts: 19,366
Thanks: 787
Thanked 3,258 Times in 3,054 Posts
Quote:
Originally Posted by Pawan Kumar View Post
will above command standard?
I don't think your question translated.
Quote:
I have only concern is that wthether the above command generates tar file temporarily then delete afterwards? or it not at all generates tar file?
No, it compresses in-place, with no need for temporary file.

Both methods do, actually.
Sponsored Links
    #5  
Old 10-24-2012
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 18 September 2014, 7:34 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,248
Thanks: 45
Thanked 816 Times in 643 Posts
Quote:
Originally Posted by Pawan Kumar View Post
tar -pczf MyBackup.tar.gz <file which needs to be inside>

will above command standard?

I have only concern is that wthether the above command generates tar file temporarily then delete afterwards? or it not at all generates tar file?
"tar" is a standard command. The standard version of "tar" has no "-z" switch at all, therefore you can't expect it to be able to understand it. Only the GNU version of "tar" has this extension. Therefore the second version Corona688 told you should be preferred. It will work everywhere, including GNU systems, while your version will work ONLY on GNU systems:


Code:
tar -cf - <files/paths to be included> | gzip > /path/to/output.tgz

It is generally better not to rely on extensions to the standard but to use only what the standard defines. By "standard" i mean POSIX here.

I hope this helps.

bakunin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
KSH - help needed for creating a script to generate xml file from text file Yoodit Shell Programming and Scripting 0 06-21-2011 02:07 AM
Help with creating a text file in perl with file creation date. msrahman Shell Programming and Scripting 5 04-26-2011 07:15 PM
creating separate directories according to file extension and keeping file in different directory as Deekay.p UNIX for Dummies Questions & Answers 2 07-28-2010 10:00 AM
Read a file and search a value in another file create third file using AWK King Kalyan Shell Programming and Scripting 11 06-19-2009 12:05 AM
ls > file - Creating file containing the list of all files present in a directory pranavagarwal Shell Programming and Scripting 1 09-26-2008 08:37 PM



All times are GMT -4. The time now is 07:41 AM.