dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

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 ...


Home > Database Forum > Operating Systems > shell > tar archiving with base name only [slightly OT]

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 11-08-2008, 08:32 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default tar archiving with base name only [slightly OT]

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.


Cheers,

--
Seb
Reply With Quote
  #2  
Old 11-08-2008, 09:04 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: tar archiving with base name only [slightly OT]

On 2008-11-09, Seb wrote:
> 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
Reply With Quote
  #3  
Old 11-09-2008, 12:28 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: tar archiving with base name only [slightly OT]

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... :-)
Reply With Quote
  #4  
Old 11-10-2008, 10:46 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: tar archiving with base name only [slightly OT]

On 2008-11-09 17:28, Sven Mascheck wrote:

> > 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
Reply With Quote
  #5  
Old 11-10-2008, 01:19 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: tar archiving with base name only [slightly OT]

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
Reply With Quote
  #6  
Old 11-10-2008, 03:15 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: tar archiving with base name only [slightly OT]

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):
Reply With Quote
  #7  
Old 11-12-2008, 12:48 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: tar archiving with base name only [slightly OT]

On Nov 11, 12:15 am, Sven Mascheck wrote:
> 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
Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 03:02 PM.