ex () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
Some might rather have backup put key files somewhere else ie in .backup or /backup
You could do that pretty easily too...
Code:
bu () { cp $1 /backup/${1}-`date +%Y%m%d%H%M`.backup ; }
This would put all files into /backup/
Code:
bu () { cp $1 ~/.backup/${1}-`date +%Y%m%d%H%M`.backup ; }
This would put all the files into ~/.backup (in your home directory)
this would require that you are IN the directory of the file you want to backup. You would move the file with the bu FILENAME ...... you could not use the /path/filename method like i listed above.
Here's a twist to so you can maintain your backed-up file in the same directory structure in your .backup directory
Code:
bu ()
{
if [ "`dirname $1`" == "." ]; then
mkdir -p ~/.backup/`pwd`;
cp $1 ~/.backup/`pwd`/$1-`date +%Y%m%d%H%M`.backup;
else
mkdir -p ~/.backup/`dirname $1`;
cp $1 ~/.backup/$1-`date +%Y%m%d%H%M`.backup;
fi
}