开发者

How to create flat tar archive

开发者 https://www.devze.com 2023-02-08 07:39 出处:网络
my tree command returns tmp `开发者_如何学Go-- t `-- e |-- foo.ps `-- s |-- bar.ps `-- t `-- baz.ps How can I create archive ps.tar.gz in tmp directory with following structure:

my tree command returns

tmp
`开发者_如何学Go-- 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

?


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


outfile=$(pwd)/ps.tar;find . -type f | while read file; do 
    tar rf $outfile -C $(dirname $file) $(basename $file)
done
gzip $outfile
0

精彩评论

暂无评论...
验证码 换一张
取 消