So I'm pretty new to Ubuntu and the whole Linux environment though I'm a computer scientist and I want to become familiar with the basic commands.
At the moment I am working with .tar and .tar.gz files and I have a problem creating one of them.
Let's assume I have the following file structure:
./
|-> a |-> Release |-> [some files]
|-> b |-> Release |-> [some files]With the following commands I currently create my tar-file:
tar -cvf ../archive.tar a
tar -rvf ../archive.tar bNow my archive.tar also has the format
archive.tar
|-> a |-> Release |-> [some files]
|-> b |-> Release |-> [some files]Now let's come to my question: How can I achieve the following three archive structures given the said file structure above:
Add a common base folder
archive.tar |-> baseFolder |-> a |-> Release |-> [some files] |-> b |-> Release |-> [some files]Rename the folders
archive.tar |-> aChangedFolderName |-> Release |-> [some files] |-> bChangedFolderName |-> Release |-> [some files]Add a common base folder and rename the folders
archive.tar |-> baseFolder |-> aChangedFolderName |-> Release |-> [some files] |-> bChangedFolderName |-> Release |-> [some files]
For me it doesn't matter if it just can be accomplished in multiple steps, at least I hope I can do it. And: #1 would be the most important to me.
1 Answer
You can do 1. with the following command:
tar cvf archive.tar --transform 's,^,baseFolder/,' a bThe archive will contain:
$ tar tvf archive.tar
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/a/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/a/foo
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/b/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/b/barFor 2. you can run tar with multiple --transform options:
tar cvf archive.tar --transform 's,^a,changed_a,' --transform 's,^b,changed_b,' a bThe archive will contain:
$ tar tvf archive.tar
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 changed_a/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 changed_a/foo
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 changed_b/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 changed_b/barFor 3. you can combine 1. and 2. as follows:
tar cvf archive.tar --transform 's,^a,changed_a,' --transform 's,^b,changed_b,' --transform 's,^,baseFolder/,' a bThe archive will contain:
$ tar tvf archive.tar
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_a/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_a/foo
drwxrwxr-x sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_b/
-rw-rw-r-- sylvain/sylvain 0 2015-03-18 12:47 baseFolder/changed_b/bar 2