Hello blogweb. This week I’ll be posting some of my bash scripts that I use on a regulare basis. I’m not sure I’ll get to every day but I’ll do what I’m able. With that:
Crush
I tend to do quite a bit of compressing files for uploading and I cannot always seem to remember the options and order of those options that tar needs. So I built a bash script that does it for me. I call it Crush and it’s syntax is basic:
crush <file1> <folder>... <archive-name>
If no archive name is given, crush will use the name of the last file entered.

#!/bin/bash
# crush - archive and compress file/folder(s)
# Extract last parameter (archive filename) for variable
ARCHIVENAME="${!#}"
# Remove last paramerter (archive filename) for file/folder list to compress
length=$(($#-1))
FILES=${@:1:$length}
# Usage - display usage if no parameters are given
if [[ -z $@ ]]; then
echo "crush <file> <folder>... <compressed-name>.tar.gz"
exit
fi
# Tar the files, name archive after last file/folder if no name given
if [[ ! -f $ARCHIVENAME ]]; then
tar -czvpf "$ARCHIVENAME".tar.gz $FILES; else
tar -czvpf "$ARCHIVENAME".tar.gz "$@"
fi
Awesome, I’ve been getting into more and more bash scripting so this is very cool. Keep em coming. Always looking for ideas.
Nice to know that you could make use of it. Danke.