开发者

How to create flat tar archive

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜