Register
It is currently Sat Sep 20, 2014 1:56 am

compress files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Fri Jun 19, 2009 3:00 am   

Joined: Fri Jun 19, 2009 2:55 am
Posts: 1
Hi all,

I'm a newbie in script programming and have to compress several files from one directory to another location
where the original files should uncompressed at their location.
The script should ask for a src-dir and the destination-dir and should also compress opened files.

Does anyone have an idea how to realize this or any links to scriptpages where I can find a script like this ?

Thanks in advance

Dys


Top
 Profile  
 PostPosted: Sun Jun 21, 2009 3:26 am   

Joined: Sun Jun 21, 2009 3:23 am
Posts: 4
Code:
#!/bin/bash

if [ $# -ne 2 ]; then
        echo "ERROR - Usage: $0 src_dir dst_dir"
        exit 2
fi

# Execute
tar cvf - $1 | gzip -9 > $2/$1.tar.gz


You need to supply 2 arguments, one is the source directory and the other is the destination. An example is:
Code:
[twantrd@twantrd tmp]$ ./twantrdtest.sh
ERROR - Usage: ./twantrdtest.sh src_dir dst_dir


Make some test directories and some test files first and run the script to see if it does what you want. Have fun.

-twantrd


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP