zip up huge folder via ssh

Discussion in 'Apache' started by stephan2307, Mar 2, 2011.

  1. #1
    How can I zip up a folder (or tar etc ) (folder contains loads of jpg images) via ssh.

    Ideally I want each zip to contain 1000 images each. Any idea how I can do this?

    Thanks.
     
    stephan2307, Mar 2, 2011 IP
  2. abiko

    abiko Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here you go, place this code in file and place it in the directory where your images are at:


    Code:
    
    #!/bin/bash
    #
    #------------------------------------------------------------------------------
    #       Script fill create tar.gzs with n number of files in them
    #       just change the num_files variable.
    #       
    #       Place the script into the directory you want to generate the files
    #------------------------------------------------------------------------------
    count=0
    file=0
    num_files=1000
    
    echo ">>> STart now <<<"
    for i in `find . -type f`;do
            if [ "$count" -eq "$num_files" ]; then
            echo "--- Creating TAR file number $file ---"
                    count=0;
                    file=$(( $(echo $file) +1));
            fi
            count=$(( $(echo $count)+1));
            tar czf images.$file.tar.gz $i;
    done;
    Code (markup):
    When you've saved the file just execute chmod +x ./script.sh and then run it with:

    ./script.sh

    Once done, you'll have archives :
    images.0.tar.gz
    images.1.tar.gz etc in your directory.

    You can move them to other location by:

    mv ./images.*.tar.gz /other/location/
     
    abiko, Mar 3, 2011 IP
  3. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #3
    cheers. will give it a go ;)
     
    stephan2307, Mar 3, 2011 IP