LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 02: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 02:05 AM.
 
Old 06-20-2013, 02:13 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 02:33 AM   #3
RMLinux
Member
 
Registered: Jul 2006
Posts: 260

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


Reply



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 04:37 AM
Piping tar bzcat to add a file to a tar.bz2 archive DaveQB Linux - Software 0 06-02-2008 08:28 PM
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 05: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 03:15 AM
nfs a file shares ok via file mngr but not command line. Suse 9.1 acummings Linux - Networking 2 10-09-2004 02:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:33 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
Open Source Consulting | Domain Registration