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 09-30-2004, 06:24 AM   #1
hari_s_82
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Rep: Reputation: 0
Redirecting stdout to tar


Hi,

Can anyone tell me how i can redirect stdout to a tar file.

This is what i want to do...

I have a file, say xyz. I want to create a new tar file(say 123.tar) in which xyz appears with a new name say "abc", i don't want to create a copy of xyz or modify it. I want to "cat xyz" and redirect that output to "tar". Is this possible.


Thanks,
Hari.
 
Old 09-30-2004, 07:52 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Here is an example of piping the output tar to transfer from one directory to another.
$ cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)

I don't think you could pipe extracted files through a pipe into tar. What you can do is first extract the abc file, rename the file to xyz, --delete the abc file in the archive and --append the xyz file.

$ tar xvf collection.tar abc
$ mv abc xyz
$ tar --delete --file=collection.tar abc
$ tar --append --file=collection.tar xyz

If what you had wanted to do is transfer files from one directory to another adding a file to the list, it would go someting like this:

$ cd sourcedir; tar --append --file=- . ~/xyz | (cd targetdir; tar-xf -)

This assumes you have the xyz file in your home directory.
 
Old 09-30-2004, 08:12 AM   #3
hari_s_82
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Original Poster
Rep: Reputation: 0
Re

Hi,

Thank you very much for your answer. I would also like to know whether i can accomplish the following action.

curent directory - ~

i have a file here "me.txt"

i want to create a new tar "mytar.tar" which is in say "/var/temp"

i want to add this file "me.txt" as "me1.txt" in this tar without creating a temorary copy of "me.txt" and without moving/renaming it in any way.(space is a constraint, it is due to this space constraint that i enquired whether i can pipe "me.txt" directly to the tar file.)


Thanks
Hari.
 
Old 10-08-2004, 01:59 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
I don't think you can do it that way. Why do you need to change the name of the file.

Perhaps if you created a link named xyz which refers to file abc, and you used the -h modifier.
 
Old 10-08-2004, 02:32 AM   #5
hari_s_82
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Original Poster
Rep: Reputation: 0
Re

Hi,

I want to rename the file to bring some sort of consistency to the name of the files i archive. By this i mean if the orignal location of the file was say /home/user/user1/me.txt, i would like to add say "user1" to the name of the file when i add it to the archive to indicate that the file orignally belonged to "user1".

I didn't want to copy as there is a space constraint.

The -h option that u said works perfectly for me. Thanks a lot for all your help. Thanks.


Hari.
 
Old 10-08-2004, 02:32 AM   #6
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
With a hard link, it would work, and it wouln't take more space:
> ln old_name.txt new_name.txt
> tar cf the.tar new_name.txt
> rm -f new_name.txt

Yves.
 
Old 10-08-2004, 02:49 AM   #7
hari_s_82
LQ Newbie
 
Registered: Sep 2004
Posts: 20

Original Poster
Rep: Reputation: 0
Re

Hi,

Thanks a lot for your reply. Thanks.


Hari.
 
  


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 decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 03:48 AM
Redirecting to file and stdout Quantum0726 Programming 3 11-14-2005 09:35 PM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 08:55 AM
redirecting stdin and stdout with pipes: convincing apps they're for a terminal? prell Programming 1 09-02-2004 07:38 AM
Redirecting stdout from tar to a text file. heatlill Programming 2 01-22-2002 11:27 AM


All times are GMT -5. The time now is 02:58 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