tbz file from pkg

Polytropon freebsd at edvax.de
Sat Jul 25 21:29:26 UTC 2020

On Sat, 25 Jul 2020 17:15:53 -0400, Lonnie Cumberland wrote:
> Hi All,
> I find that I do not need a fully blown shell script, so I cobbled together
> a single set of shell commands that will convert "*.txz" file to "*.tbz"
> files and it seems to work.
> # find *txz -iname '*txz' | while read txz; do echo "Found: $txz";
> name=$(echo "$txz" | sed -e 's/\.[^.]*$//'); mkdir -p tmp/$name; tar -xjf
> $txz -C tmp/$name; cd tmp/$name; tar cvfj ../../$name.tbz .; cd ../..; rm
> -Rf tmp/$name; rm -Rf tmp; done
> maybe it will be of help to others as well.

Allow me a little addition:

The first parameter to find should be a directory. If you are
already in the directory where the files are stored, use ".".
Note that using -iname will also process *.Txz or *.TXZ, if
that is desired.

If you want to remove the extension, you don't need to use sed
for this: The shell - I assume it is sh - can do this for you:
For example, if txz="foo-1.2.3_4,5.txz", then ${txz%.*} or
${txz%.txz} will be "foo-1.2.3_4,5".

See section "Parameter Expansion" in "man 1 sh" for details. :-)

Another suggestion would maybe be to omit the "store, repackage,
delete" step and use a pipe. Maybe it would also be possible
to omit the "extract" part altogether: Have xz only decompress
(result is a regular tar file), then bzip2 recompress, that could
also be possible without a temporary file if you can use |.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list