tar archiving with base name only [slightly OT] - shell
This is a discussion on tar archiving with base name only [slightly OT] - shell ; Hi, Going through the lengthy list of tar options, I cannot find one that allows the creation of an archive using only the base name of files. Say we're creating an archive like: tar -cvvzf tararch.tgz file1 subdir/file2 ~/file3 The ...
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| Going through the lengthy list of tar options, I cannot find one that allows the creation of an archive using only the base name of files. Say we're creating an archive like: tar -cvvzf tararch.tgz file1 subdir/file2 ~/file3 The archive will have the same directory structure. Any advice on creating an archive containing only base names of the files? Thanks. Cheers, -- Seb |
|
#2
| |||
| |||
|
On 2008-11-09, Seb > Hi, > > Going through the lengthy list of tar options, I cannot find one that > allows the creation of an archive using only the base name of files. > Say we're creating an archive like: > > tar -cvvzf tararch.tgz file1 subdir/file2 ~/file3 > > The archive will have the same directory structure. Any advice on > creating an archive containing only base names of the files? Thanks. Try this: tar -cvvzf tararch.tgz $(find file1 subdir/file2 ~/file3 -exec basename {} \; -- v4sw5RUYhw2ln3pr5ck0ma2u7Lw3+2Xm0l6/7Gi2e2t3b6AKMen5+7a16s0Sr1p-8.12/-6.56g6OR |
|
#3
| |||
| |||
|
Seb wrote: > tar -cvvzf tararch.tgz file1 subdir/file2 ~/file3 > > The archive will have the same directory structure. Any advice on > creating an archive containing only base names of the files? pax knows ed-like in-line renaming: pax -w -f arch.tar -s ',.*/,,' [...] If you use Linux: It's a traditional utility, also specified by SUS, and implemented on almost all commercial and BSD flavours. The GNU project in contrast doesn't provide one. (It looks to me as if it was repeatedly disregarded in favour of GNU tar). But there are BSD ports to Linux, and star from Jörg Schilling also knows pax. pax combined the incompatible tar and cpio archiving functionality, hence the name ("peace"). (But the GNU project apparently was not very impressed by such ideas... :-) |
|
#4
| |||
| |||
|
On 2008-11-09 17:28, Sven Mascheck > > tar -cvvzf tararch.tgz file1 subdir/file2 ~/file3 > pax knows ed-like in-line renaming: > pax -w -f arch.tar -s ',.*/,,' [...] We have something similar in GNU tar, too... --transform=EXPRESSION use sed replace EXPRESSION to transform file names tar -cvzf tararch.tgz --transform='s|.*/||' files... -- VÃ*tor De Araújo http://huangho.net76.net |
|
#5
| |||
| |||
|
Sven Mascheck wrote: > Seb wrote: >> tar -cvvzf tararch.tgz file1 subdir/file2 ~/file3 >> >> The archive will have the same directory structure. Any advice on >> creating an archive containing only base names of the files? > > pax knows ed-like in-line renaming: > > pax -w -f arch.tar -s ',.*/,,' [...] > > If you use Linux: > > It's a traditional utility, also specified by SUS, and implemented > on almost all commercial and BSD flavours. The GNU project in contrast > doesn't provide one. (It looks to me as if it was repeatedly disregarded > in favour of GNU tar). But there are BSD ports to Linux, and star > from Jörg Schilling also knows pax. > > pax combined the incompatible tar and cpio archiving functionality, > hence the name ("peace"). (But the GNU project apparently was not > very impressed by such ideas... :-) My Fedora system has pax installed. From the man page is seem as if pax should be able to archive and re-create extended attributes, including ACLs and SE Linux labels. But I have never gotten that to work. Currently only star seems to backup and restore EAs and ACLs. Has anyone got pax to successfully backup and restore these? -Wayne |
|
#6
| |||
| |||
|
Vítor De Araújo wrote: > Sven Mascheck wrote: >> pax knows ed-like in-line renaming: > We have something similar in GNU tar, too... > --transform=EXPRESSION Indeed. The feature is pretty young and you may not count on it yet on existing installations: I just tried it on the system of my provider I'm writing this on and it confuses several transform expressions: $ tar --version tar (GNU tar) 1.16 $ find . -ls 5871954 16 drwxr-xr-x 3 ... 16384 Nov 10 20:02 . 5871956 16 drwxr-xr-x 2 ... 16384 Nov 10 19:56 ./dir 5871957 0 lrwxrwxrwx 1 ... 1 Nov 10 19:56 ./dir/b -> a 5871955 0 -rw-r--r-- 1 ... 0 Nov 10 19:56 ./dir/a $ tar cf - --transform='s,b,x,' --transform='s,.*/,,' .|tar tfv - drwxr-xr-x ... 0 2008-11-10 20:02 ./ drwxr-xr-x ... 0 2008-11-10 19:56 xdir/ lrwxrwxrwx ... 0 2008-11-10 19:56 xb -> a -rw-r--r-- ... 0 2008-11-10 19:56 xa So I looked into the Changelog: - "Support multiple --transform options" and "Apply transform_name to symlink targets" released with 1.19.90 (2008-02-04) - "New option --transform" released with version 1.15.92 (2006-06-21): |
|
#7
| |||
| |||
|
On Nov 11, 12:15 am, Sven Mascheck > Vítor De Araújo wrote: > > Sven Mascheck wrote: > >> pax knows ed-like in-line renaming: > > We have something similar in GNU tar, too... > > --transform=EXPRESSION > > Indeed. > The feature is pretty young and you may not > count on it yet on existing installations: > > I just tried it on the system of my provider I'm writing this on > and it confuses several transform expressions: > > $ tar --version > tar (GNU tar) 1.16 > > $ find . -ls > 5871954 16 drwxr-xr-x 3 ... 16384 Nov 10 20:02 . > 5871956 16 drwxr-xr-x 2 ... 16384 Nov 10 19:56 ./dir > 5871957 0 lrwxrwxrwx 1 ... 1 Nov 10 19:56 ./dir/b -> a > 5871955 0 -rw-r--r-- 1 ... 0 Nov 10 19:56 ./dir/a > > $ tar cf - --transform='s,b,x,' --transform='s,.*/,,' .|tar tfv - > drwxr-xr-x ... 0 2008-11-10 20:02 ./ > drwxr-xr-x ... 0 2008-11-10 19:56 xdir/ > lrwxrwxrwx ... 0 2008-11-10 19:56 xb -> a > -rw-r--r-- ... 0 2008-11-10 19:56 xa > > So I looked into the Changelog: > > - "Support multiple --transform options" and > "Apply transform_name to symlink targets" > released with 1.19.90 (2008-02-04) > - "New option --transform" > released with version 1.15.92 (2006-06-21): Somewhat portable but you can only give directories not individual files which may need little more tuning. I dont know what your intention, but this kind of process, will overwrite the files of same name in different directories in the TAR archive. for dir in my/dir/1 my/dir/2 your/dir/3 ; do (cd $dir ; tar -uvf ~/ mytarfile.tar * ); done |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
All times are GMT -4. The time now is 03:02 PM.




Linear Mode