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
精彩评论