0

I have a process that creates a tar file with copies of files that need to be updated.

I want to backup existing files before overwriting with the new files.

I've tried

tar cf backup.tar -T `tar tf updated.tar`

Which didn't work. If I pipe the output from tar tf to a file, then use that as the -T param it works:

tar tf updated.tar > list; tar cf backup.tar -T list

But it seems to me that I should be able to accomplish this in one command. Is it possible?

3

Specify stdin as input file, e.g.:

tar tf updated.tar | tar cf backup.tar -T -

1

The -T option is specifically looking for a file, not a list. Your first attempt passes a list to -T, which is probably why it doesn't work. I would try something like:

tar tf updated.tar | xargs tar cf backup.tar
  • 1
    This may fail in some rare cases. The maximum number of allowed command line arguments is restricted. See getconf ARG_MAX. – user86064 Mar 13 '13 at 17:20
  • Good point... so H. Dirk Schmitt's answer is probably better. – John Mar 13 '13 at 17:27
  • @H.-DirkSchmitt: It should be noted that xargs normally takes care of this by splitting the command in multiple invocations. (It just doesn't work as expected here since a second tar c overwrites the first output.) – grawity Mar 13 '13 at 17:36
-1

I use this commande:

tar cf backup.tar `tar tf updated.tar`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.