Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need to setup some kind of script to go through a set of folders, compressing each one, and only leaving the compressed copy of each. How can I do that?

share|improve this question
2  
The title doesn't pretty much say it. What do want to do exactly? Do you want a script that performs these actions? What type of archive do you want? What order do you want to execute? –  André Stannek Jul 22 '12 at 14:50
    
To be exact I want to 1. compress a folder, 2. After it compresses that folder, delete that folder (Where the backup compressed file remains) 3. Pick the next folder on the list and repeat. I Suppose I do want a script. –  TardisGuy Jul 22 '12 at 15:15
    
How does the list with folders look? –  André Stannek Jul 22 '12 at 15:16

1 Answer 1

up vote 3 down vote accepted

This script takes a list of folders as arguments. Save it as e.g. backup.sh and call it like this:

./backup.sh Folder1 Folder2

You have to make the script executable before this:

chmod u+x backup.sh

Here comes the script:

#!/bin/bash
for folder in "$@"
do
    tar czf $folder.tgz $folder
    rm -R $folder
done

Tell me if this is not what you need. If you are not sure what it's doing make a backup of your data before you test it ;-)

share|improve this answer
1  
It did work. ty much. –  TardisGuy Jul 27 '12 at 12:02
    
You're welcome! :-) –  André Stannek Jul 27 '12 at 12:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.