0

I have multiple text files in a folder. I must tar them in a single tar-file. I am passing (iterate) the file names through a variable. When I do that only the first file gets tarred.

Here is the code/script:

"tar -czf "+filename_+TalendDate.getDate("MMddyyyy")+".tar.gz "+((String)globalMap.get("tFileList_3_CURRENT_FILE"))
3
  • 1
    Please edit your question to include the script you are currently using.
    – DavidPostill
    Commented Jun 1, 2015 at 16:58
  • @DavidPostill: I have included the code/script
    – Kiran
    Commented Jun 1, 2015 at 17:18
  • Any specific reason why a tar cf mytarball.tar *.txt cannot be used?
    – Hennes
    Commented Jun 1, 2015 at 20:26

1 Answer 1

0

The way you have it, all the files are actually being tarred, but they're actually overwriting each other. Simply, it can't be done the way you're trying, but you have two options:

  1. Concatenate all the filenames together and call tar exactly once with all of them. This is the cleaner method.
  2. Use replace (r) or update (u) flags to enable appending to the archive. To do so, you must disable compression (remove z flag).
2
  • Thanks for replying BowlesCR, Could you please explain the first option. I didn't understand it as I am new to this.
    – Kiran
    Commented Jun 3, 2015 at 5:25
  • I'm not sure what language you're scripting in, but effectively rework your script to do tar czf file.tgz A B C instead of trying to do tar czf file.tgz A, tar czf file.tgz B, tar czf file.tgz C
    – BowlesCR
    Commented Jun 3, 2015 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .