Report inadequate content

Script for compressing files with gzip within the terminal with date

{
}

This is a simple bash script to compress in tar.gz (gzip) format a file or folder appending date to file name.

Save this file as gzip.sh and give it execution permissions. From terminal i could be: chmod 755 gzip.sh
This script does the following:

  • Checks if you passed exactly 2 arguments
  • Compresses your source
  • Adds the date on the resulting filename
  • Optionally changes permissions of your filename (uncomment line chown and put the desired user:group)

Script:

#!/bin/bash
# Albert Lombarte
#
if [ $# != 2 ]
# There must be two arguments
then
    echo "--USAGE: $0 source target"
    exit 1
fi

FILENAME=`date "+%Y-%b-%d_$2"`
WHAT=$1

#======================================
echo "-- STARTED compression of $WHAT into $FILENAME"

#Use 'sudo' command before commands if needed

tar -c --gzip -f $FILENAME $WHAT
#chown alombarte:bckgroup $FILENAME

echo "-- FINISHED $WHAT"
echo ""
exit 1

or the same with less stuff...

#!/bin/bash
# Albert Lombarte

if [ $# != 2 ]
then
    echo "--USAGE: $0 source target"
    exit 1
fi

tar -c --gzip -f $1 $2

This example ...will result in 03-Aug-2005_alombarte.tar.gz

./gzip.sh /home/alombarte alombarte.tar.gz

{
}
{
}

Comments Script for compressing files with gzip within the terminal with date

muchas gracias por el aporte..., pero tienes algo de pueda comprimir desde una lista de directorios
helson helson 02/07/2013 at 16:25

Leave your comment Script for compressing files with gzip within the terminal with date

Log in to Obolog, or create your free blog if you are not registered yet.

User avatar Your name