Make Tar + gzip ignore directory paths
Is it possible, when making a tar + gzip through the 'tar c ...' command, to have the relative paths will be ignored upon expanding?
For example,
tar cvf test.tgz foo ../../files/bar
And then expanding the test.tgz with
tar xvf test.tgz
gives a directory containing:
foo file开发者_如何转开发s/bar
I want the directory to contain the files:
foo bar
Is this possible?
If all the paths begin with the same initial list of directories then you can use e.g. tar cvf test.tgz -C ../.. other/dir
. Beware that the shell won't expand wildcards in pathnames "properly" however because -C
asks tar
to change directory.
Otherwise, the only way I've ever come up with is to make a temporary directory filled with appropriate symlinks and use the -h
option to dereference through symlinks. Of course that won't work if some of the files you want to store are actually symlinks themselves.
精彩评论