Shell-scripts/multicompressor

36 lines
473 B
Bash
Executable File

#!/bin/bash -e
[[ -z $1 ]] &&
{
echo -e "Usage: `basename $0` (file/folder) to compress "
exit
}
FILE=$(basename $1)
[[ -z $2 ]] &&
{
echo -e "Usage: `basename $0` $FILE [ tar.gz | tar.bz2 | tar.lbz2 | tar.xz | tar.lz ]"
exit
}
tar -cf $FILE.tar $FILE
case "$2" in
tar.gz)
gzip $FILE.tar
;;
tar.xz)
xz -T $(nproc) $FILE.tar
;;
tar.bz2)
bzip2 $FILE.tar
;;
tar.lbz2)
lbzip2 -9 $FILE.tar
;;
tar.lz)
plzip -5 -n $(nproc) -v $FILE.tar
;;
esac