#1
  1. No one Important
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Australia
    Posts
    524
    Rep Power
    14

    Creating tar file


    Howdy,

    Can someone help me with the correct command line to create a recursive tar.gz file on a directory structure??

    Cheers
  2. #2
  3. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    83
    "man tar" for all the options.

    or
    tar cvf poop.tar /poop ; gzip poop.tar

    or

    tar cvfz poop.tar.gz /poop
    Last edited by Hero Zzyzzx; January 3rd, 2002 at 10:33 PM.
  4. #3
  5. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    tar -zpscf tarfilename.tar.gz directory/*

    Here's a Perl script that will create a recursive tarfile, and name it with the date and time embedded in the filename. I usually place it in /usr/local/bin. Just call it while adjacent to the directory you want to archive, using the directory name as the argument:

    myscript directory_name

    or

    myscript directory_name/

    Code:
    #!/usr/bin/perl -w
    $dir_in=shift(@ARGV);
    chomp($dir_in);
    $dir_in =~ tr/\///d;
    print "Archiving $dir_in/* ...\n";
    use POSIX qw(strftime);
    $now_string = strftime "%m-%d-%Y_%H%M", localtime;
    $tarname=$dir_in."_".$now_string.".tar.gz";
    $execstring="tar -zpscf ".$tarname." ".$dir_in."/*";
    #print($execstring); # uncomment to debug
    system($execstring);
    print("\n");
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  6. #4
  7. No one Important
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Australia
    Posts
    524
    Rep Power
    14
    Hey there thanks for the posts..... I found that the

    tar cvf poop.tar /poop works for me however some of the files in the tar file have not recorded the directory the files have come from.. is there an easy way to fix this? does it have something to do with the size of the archive file? etc etc.....

    what is the command to exclude a directory from the archive??
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    7
    Rep Power
    0
    do not forget that the output tar file should be is other directory

IMN logo majestic logo threadwatch logo seochat tools logo