LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   TAR subdirectory question (https://www.linuxquestions.org/questions/linux-newbie-8/tar-subdirectory-question-821074/)

duffsterlp 07-20-2010 01:54 PM

TAR subdirectory question
 
Hi all.
I'm working with an already existing TAR file and I'm trying to insert a file into a subfolder of the TAR archive. Is there a simple way to do this? I don't want to put it in the directory where the TAR is pointing and archive again because it is a long process to archive everything; I want to put it directly into the subfolder of the TAR.

I want to do something like: tar -cf test.tar:/subfolder text.txt

Thanks

irmin 07-20-2010 02:13 PM

Try calling tar with command "r" (append):
Code:

tar rf test.tar subfolder/text.txt
Or use the command "u" (update).

duffsterlp 07-20-2010 02:24 PM

Quote:

Originally Posted by irmin (Post 4039836)
Try calling tar with command "r" (append):
Code:

tar rf test.tar subfolder/text.txt
Or use the command "u" (update).

Maybe I didn't make myself clear. Text.txt cannot be in the subfolder but I want it to appear in subfolder inside the TAR.
I meant to use an r in my original message instead of c.
Something like tar rf test.tar:/subfolder text.txt

irmin 07-20-2010 02:54 PM

Ok, then try that:
Code:

tar rf test.tar --transform 's%^%subfolder/%' test.txt
You could also try to create a directory 'subfolder', put your file inside this folder and just add this file.

duffsterlp 07-20-2010 03:03 PM

When I do that I get the following. I created test.tar and test.txt to try it.

sh-3.2$ tar rf test.tar --transform 's%^%subfolder/%' test.txt
tar: unrecognized option `--transform'
Try `tar --help' or `tar --usage' for more information.
sh-3.2$

Maybe that option is deprecated?

irmin 07-20-2010 03:10 PM

This option is a GNU extension to tar.

duffsterlp 07-20-2010 03:24 PM

I guess that means my computer doesn't support it? Then, how do I get that command to work on my machine? Is there a similar command that is not part of the GNU extension?

irmin 07-20-2010 03:30 PM

I looked at the tar manual and info pages and the only way, as far as I see, is:
Code:

mkdir subfolder
mv test.txt subfolder
tar rf test.tar subfolder/test.txt

But you can download GNU tar (ftp://ftp.gnu.org/gnu/tar) and install it in addition to your native tar command.

duffsterlp 07-20-2010 03:41 PM

Alright. Thanks for all the help!


All times are GMT -5. The time now is 03:06 AM.