Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have created a tar.gz file (using the GUI, not the command line). How can I update it with a command that new files are added and modified files are updated, too?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

You'd normally use the -u flag for this. From tar's man page:

 -u, --update
       only append files newer than copy in archive

so this sequence will do what you need:

# First create the tar file. It has to be UNCOMPRESSED for -u to work
tar -cvf my.tar some-directory/
# ... update some files in some-directory
# ... add files in some-directory
# Now update only the changed and added files
tar -uvf my.tar some-directory/
# Compress if desired
gzip my.tar

For a slightly more detailed look, see here: http://www.gnu.org/software/tar/manual/html_node/how-to-update.html

share|improve this answer
    
Hi, tar -cvxf is not valid. So I had to change 'x' for 'z'. Then I tried this: tar -uvzf docs.tar Documents/ which does not work. tar: Cannot update compressed archives. Try tar --help' or tar --usage' for more information. However when I gave this: tar -u docs.tar Documents/ I got this: tar: Options -Aru' are incompatible with -f -'. Am I doing something wrong? –  xpanta Mar 14 '13 at 7:12
    
I corrected the command to use "z". You're right, I was giving conflicting commands (e.g. -c for create and -x for extract). I also corrected it to use uncompressed tar files based on your error message. What fails in your command is that you're not saying which tar file to operate on. It should be tar -uf docs.tar Documents/ –  roadmr Mar 14 '13 at 13:36

If you want to update a particular file in *.tar.gz file, just do the following:

Enter vi from where the tar file is available

/home>vi

For eg., if you want to modify simple.tar.gz which is under /home/test/ directory the:

/home/test>vi

And in the empty editor enter :n simple.tar.gz and press Enter you will get the list of folders and files move the cursor where u want to modify And click Enter. It will shown the vi editor of the particular file. Then i option to change the file. After the successful change. Press Esc key and choose :wq to write and quit the file. Then use :q to come out of the file list.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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