How to fix tar command error: file changed as we read it

Question: I am trying to create a tar archive, but the tar command fails with "error: file changed as we read it". Why am I getting this error, and how can I fix it?

Method One

A possible cause for this error is that the tar archive file being generated is also part of files being archived by tar command itself.

For example, consider the following example.

$ tar cvf backup.tar .

In this case, you are trying to archive into ./backup.tar which is obviously part of . tar command interprets that ./backup.tar is also one of input files, but is being changed during archiving, so throwing the error.

To fix the error, make sure that the output tar file does NOT belong to the file(s) being archived.

Method 2

Another solution is to use "--ignore-failed-read" option with tar command, which allows tar command to ignore and continue on unreadable files. This may help with getting around the issue.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

Leave a comment

Your email address will not be published. Required fields are marked *