Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create flat tar archive

Tags:

gzip

tar

my tree command returns

tmp
`-- t
    `-- e
        |-- foo.ps
        `-- s
            |-- bar.ps
            `-- t
                `-- baz.ps

How can I create archive ps.tar.gz in tmp directory with following structure:

tmp
|-- ps.tar.gz
|   |-- foo.ps
|   |-- bar.ps
|   `-- baz.ps
`-- t
    `-- e
        |-- foo.ps
        `-- s
            |-- bar.ps
            `-- t
                `-- baz.ps

?

like image 334
noisy Avatar asked Feb 04 '11 12:02

noisy


2 Answers

for GNU tar you can use the --xform argument. It takes a sed expression and applies it on each file name. So for removing all characters up to the last /, you may use:

tar -c --xform s:^.*/:: your-files
like image 155
Panda Avatar answered Nov 09 '22 18:11

Panda


outfile=$(pwd)/ps.tar;find . -type f | while read file; do 
    tar rf $outfile -C $(dirname $file) $(basename $file)
done
gzip $outfile
like image 44
David Hall Avatar answered Nov 09 '22 18:11

David Hall