How to create flat tar archive

隐身守侯 提交于 2019-12-09 15:15:57

问题


my tree command returns

tmp
`-- t
    `-- e
        |-- 23.ps
        `-- s
            |-- adsf.ps
            `-- t
                `-- dupa.ps

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

tmp
|-- ps.tar.gz
|   |-- 23.ps
|   |-- adsf.ps
|   `-- dupa.ps
`-- t
    `-- e
        |-- 23.ps
        `-- s
            |-- adsf.ps
            `-- t
                `-- dupa.ps

?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/4898056/how-to-create-flat-tar-archive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!