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

Was this post interesting?

Related posts

Leave your comment

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

Comments

Subversion (svn) 1.5 para Mac OS X (alombarte)
Estamos dejados de la mano de Dios.... ains!...(13 Nov)
Subversion (svn) 1.5 para Mac OS X (obokaman)
Ais... ¿cuándo alguien se va a currar un cliente GUI tan completo como TortoiseSVN ...(12 Nov)
U*Blog: blog posting from the pda (icoft)
Worldwide client base in the mobile communications space.See the details at ...(08 Nov)
U*Blog: blog posting from the pda (icoft)
WORLDWIDE client base in the cell phone sector. Tremendous opportunity to get in the stock now. ...(08 Nov)
Cómo reiniciar o resetear un ipod colgado (fermin)
necesito saber como hacer eso pero para mi ipod touch no puedo se quedo trabado  mientras le...(06 Nov)

Login

Otros blogs de nexoBlogs: