nexoBlogs network
Anonymous Anonymous

Script for compressing files with gzip within the terminal with date

Wednesday, 14 de September del 2005
filed under , ,

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

Related to Script for compressing files with gzip within the terminal with date

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

Leave your comment
You need javascript to be activated on irder to leave comments

Login in OboLog, or create free blog if you don't have one yet.

Then we'll remember your data and show your avatar in your comments.

Sponsors

Login

Otros blogs de nexoBlogs: