J'ai créé des archives tar avec un path absolu pour save les files.
/home/mydir/dir1/dir2/dir3/file1.dat /home/mydir/dir1/dir2/dir3/file2.dat /home/mydir/dir1/dir2/dir3/file3.dat
Je voudrais décompresser ces archives en sautant la partie principale du path, /home/mydir/dir1
. Mes files doivent être restaurés dans n'importe quel directory avec cette structure:
dir2/dir3/file1.dat dir2/dir3/file2.dat dir2/dir3/file3.dat
Comment puis-je le faire avec la command tar, ou d'une autre façon?
Si vous utilisez GNU tar, il existe une option pour supprimer certains membres path path lors de l'extraction:
`--ssortingp-components=number' Ssortingp given number of leading components from file names before extraction. For example, suppose you have archived whole `/usr' hierarchy to a tar archive named `usr.tar'. Among other files, this archive contains `usr/include/stdlib.h', which you wish to extract to the current working directory. To do so, you type: $ tar -xf usr.tar --ssortingp=2 usr/include/stdlib.h
(De la documentation GNU tar .)
Dans votre cas, --ssortingp=3
devrait s'appliquer.
Avec tar tar (trouvé sur Linux non embedded et Cygwin), vous pouvez appliquer un rlocation d'expression régulière aux paths lors de l'ajout de membres à une archive ou lors de leur extraction avec l' option --transform
.
tar -xf foo.tar --transform='s!^/home/mydir/dir1/!!'
Avec * tar BSD (y compris sur OSX), il existe une option similaire appelée -s
.
tar -xf foo.tar -s '!^/home/mydir/dir1/!!'
POSIX a la command pax
avec la même option que BSD tar.
pax -r <foo.tar -s '!^/home/mydir/dir1/!!'