Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I want to divide a directory into a no. of archives with tar. For example I have a big directory 'mydir'. I want to make 5 archives mydir1.tar, mydir2.tar, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2005
    Location
    Germany
    Posts
    69

    divide a directory into multiple archive files with tar


    Hi,
    I want to divide a directory into a no. of archives with tar.
    For example I have a big directory 'mydir'. I want to make 5 archives mydir1.tar, mydir2.tar, ... mydir5.tar from my big directory ‘mydir’.
    Eventually I would like to have a text file with the content of every archive (filename and date).

    How can I do that? I didn’t find any tar option which could help me.



    ddaas

    Last edited

  2. #2
    Just Joined!
    Join Date
    Feb 2005
    Posts
    9
    You can write a script to do that:

    Code:
             #!/bin/sh
             # USAGE
              function usage(){
                  cat << EOF
                       -h print this help and exit.
                       -n tar archive name
                       -d directory to tar
               EOF
               &#125;
    
            # Default directory 
             dir=
            # Default tar name
             tar=
    
             while &#91; $# -ne 0 &#93;; do
                 case $1 in
                          -h&#41;
                               usage
                               exit
                               ;;
                         -n&#41;
                              shift
                              tar=$1
                              ;;
                         -d&#41;
                              shift
                              dir=$1
                              ;;
                         *&#41;
                             echo "Unknown option $1" >&2
                             exit 1;
                             ;;
                   esac
             done
     
             # Create the tar file
              tar cf $tar.tar $dir
             # Create the text file
              ls -Rl $dir > $tar.txt
    If you call your script 'myscript' then:
    Code:
     myscript -n tarname -d directory
    should create a tar archive of name 'tarname.tar' with a file 'tarname.txt' listing every files in 'directory' with their dates.
    If you assign a value to the variable 'dir' for example you can call
    Code:
    myscript -n tarname
    Hope that helps.

  3. #3
    Just Joined!
    Join Date
    Jan 2005
    Location
    Germany
    Posts
    69
    thanks,
    I'll try your script.


    ddaas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •