Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    23

    Unanswered: script with selection date for tar

    Hello

    I need a little help in my installation. We need make a tar all days with a directory with many files to selected for a date. I trying execute this command in a script

    find /tmp/files/* -mmin +1440 -a -type f -exec tar -cf /tmp/comp.Z {} \;

    it's running ok, but only contain one file into the comp.Z

    Any know what is my problem?

    If any know other method for make this, it's welcome.

    Thank you

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    -exec ... {} will run the command for each file that was found again. Thus, one "tar cf" will overwrite the tar file produced for the previous file. I would do this instead:
    Code:
    find /tmp/files/* -mmin +1440 -a -type f | xargs tar -cf /tmp/comp.Z
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Sep 2003
    Posts
    23
    Now it's work ok. I have still a lot of to learning

    thank you for your help

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    If you use the approach I posted above, you will run into problems as soon as a file name containing spaces is encountered. (You have the same problem in your original script as well, btw.) If you stick with "find" only, you should put double-quotes around the {}.

    What would be a good idea is to use the -r or -u options to append files to an archive:
    Code:
    find /tmp/files/* -mmin +1440 -a -type f -exec tar uf comp.tar -uf "{}" \;
    p.s: "tar" does not create a compressed file (extension .Z) unless you tell it to do so with the option -Z.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

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