LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-20-2013, 03:02 AM   #1
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Rep: Reputation: 37
How to add 1 file in .tar.gz file IN just ONE straight command line RHEL?


Hi Guys,

I know adding 1 file in tar.gz file.

Supposed we have a.txt(a.tar.gz) and b.txt(need to add) file.
The tar and zipped filename is "a.tar.gz" file.

So here's the procedure.

1. gunzip a.tar.gz

output: a.tar

2. tar -rf a.tar b.txt

output: a.tar (change in size)

3. gzip a.tar

That's it!

BUT WHAT I WANT TO ACHIEVED IS how can I run that command in one straight line?

Thank you very much.

Last edited by RMLinux; 06-20-2013 at 03:05 AM.
 
Old 06-20-2013, 03:13 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Use '&&'
Code:
 gunzip a.tar.gz && tar -rf a.tar b.txt &&  gzip a.tar
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

Using '&&' instead of ';' means each cmd only runs if the preceding one succeeded, otherwise it bails out (safer).
 
Old 06-20-2013, 03:33 AM   #3
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

Original Poster
Rep: Reputation: 37
Thank you very much Chris
Cheers!
 
  


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
How can I read a file line by line and add it to a loop in another file? astroumut Linux - Newbie 7 08-24-2009 05:37 AM
Piping tar bzcat to add a file to a tar.bz2 archive DaveQB Linux - Software 0 06-02-2008 09:28 PM
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 06:08 PM
gave wrong syntax for tar as tar -cvzf file file.tgz how to recover the file gautham Linux - General 4 04-13-2005 04:15 AM
nfs a file shares ok via file mngr but not command line. Suse 9.1 acummings Linux - Networking 2 10-09-2004 03:23 PM


All times are GMT -5. The time now is 12:41 PM.

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