Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.)
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.