I think you cannot use the -C
option like you presume in this question.
Section 6.10.1 Changing the Working Directory
in the GNU manual for tar
describes the -C
option like this,
To change the working directory in the middle of a list of file names, either on the command line or in a file specified using ‘--files-from’ (‘-T’), use ‘--directory’ (‘-C’). This will change the working directory to the specified directory after that point in the list.
‘--directory=directory’
‘-C directory’
Changes the working directory in the middle of a command line.
For example,
$ tar -c -f jams.tar grape prune -C food cherry
will place the files ‘grape’ and ‘prune’ from the current directory into the archive ‘jams.tar’, followed by the file ‘cherry’ from the directory ‘food’. This option is especially useful when you have several widely separated files that you want to store in the same archive.
Note that the file ‘cherry’ is recorded in the archive under the precise name ‘cherry’, not ‘food/cherry’. Thus, the archive will contain three files that all appear to have come from the same directory; if the archive is extracted with plain ‘tar --extract’, all three files will be written in the current directory.
There are a few more examples at the manual page...
Update:
I usually do not mix up files from different paths into a single tar-ball.
However, if that is what you desire, there are two things that can be done,
- Use the
-T
option with a list of directories/files you want to pack together.
That will collect all things together with extra path-prefixes.
- Use the
-h
option on a 'link image' directory
(you make one of those with a script to create links to files and directories of interest under a new and empty directory)
The -h
option used on such a directory will create a single tar-ball that represents the file layout under that directory.