Basic Tar Question - Directory Formatting
by onlyasians from LinuxQuestions.org on (#5CHSC)
I have a folder called test1 that contains three files: file1.txt, file2.txt, file3.txt.
Assumed Location: /home/test1/file1.txt
/home/test1/file2.txt
/home/test1/file3.txt
I have a file that that exist elsewhere: externalFile1.txt
Assumed Location: /home/otherLocation/externalFile1.txt
So, I'm attempting to tar up all the files but with externalFile1 being included in test1 folder.
What I'm currently doing:
tar czf /home/test1/ /home/otherLocation/externalFile1.txt
This created a tar file with the following hierarchy:
test1/
test1/file1.txt
test1/file2.txt
test1/file3.txt
external File1.txt
However, I want the following:
test1/
test1/file1.txt
test1/file2.txt
test1/file3.txt
test1/externalFile1.txt
I do not have the ability to copy externalFile1.txt to the test1 directory and then tar. I don't want to fix this by untarring the file to the correct location. I want to resolve this when initially tarring.
Is there a way to modify the directory structure of files you are compressing with tar?


Assumed Location: /home/test1/file1.txt
/home/test1/file2.txt
/home/test1/file3.txt
I have a file that that exist elsewhere: externalFile1.txt
Assumed Location: /home/otherLocation/externalFile1.txt
So, I'm attempting to tar up all the files but with externalFile1 being included in test1 folder.
What I'm currently doing:
tar czf /home/test1/ /home/otherLocation/externalFile1.txt
This created a tar file with the following hierarchy:
test1/
test1/file1.txt
test1/file2.txt
test1/file3.txt
external File1.txt
However, I want the following:
test1/
test1/file1.txt
test1/file2.txt
test1/file3.txt
test1/externalFile1.txt
I do not have the ability to copy externalFile1.txt to the test1 directory and then tar. I don't want to fix this by untarring the file to the correct location. I want to resolve this when initially tarring.
Is there a way to modify the directory structure of files you are compressing with tar?