I wanted to compress a directory into .tar.xz format and verify it after writing so I wrote a command like this:

tar --xz --create --verbose --verify --file myArchive.tar.xz /patch/to/my/dir

but it did not create archive and I got this two error lines:

    tar: Cannot verify compressed archives 
    try 'tar --help' or 'tar --usage' for more information.

I tried tar.gz format instead of tar.xz but got exactly same resault, what is the problem and how can I solve it?

  • Maybe avoid tar in future? Depending on the application there are a lot of alternatives - I favour afio as it is mostly a drop in replacement for tar but with more robust file formats.
    – symcbean
    Commented Nov 10, 2020 at 23:57

1 Answer 1


Section 9.8 of tar manual says:

9.8 Verifying Data as It is Stored

     Attempt to verify the archive after writing.

   This option causes `tar' to verify the archive after writing it.
Each volume is checked after it is written, and any discrepancies are
recorded on the standard error output.

   Verification requires that the archive be on a back-space-able
medium.  This means pipes, some cartridge tape drives, and some other
devices cannot be verified.

A compressed archive is not back-space-able, thus the error you receive when trying to mix both options.

The next paragraphs then mention --compare, which you should use:

   One can explicitly compare an already made archive with the file
system by using the `--compare' (`--diff', `-d') option, instead of
using the more automatic `--verify' option.  *Note compare::.

   Note that these two options have a slightly different intent.  The
`--compare' option checks how identical are the logical contents of some
archive with what is on your disks, while the `--verify' option is
really for checking if the physical contents agree and if the recording
media itself is of dependable quality.  So, for the `--verify'
operation, `tar' tries to defeat all in-memory cache pertaining to the
archive, while it lets the speed optimization undisturbed for the
`--compare' option.  If you nevertheless use `--compare' for media
verification, you may have to defeat the in-memory cache yourself,
maybe by opening and reclosing the door latch of your recording unit,
forcing some doubt in your operating system about the fact this is
really the same volume as the one just written or read.

   The `--verify' option would not be necessary if drivers were indeed
able to detect dependably all write failures.  This sometimes require
many magnetic heads, some able to read after the writes occurred.  One
would not say that drivers unable to detect all cases are necessarily
flawed, as long as programming is concerned.

Using --compare for verification, you can do:

tar --xz --create --verbose --file myArchive.tar.xz /patch/to/my/dir
tar --compare --file myArchive.tar.xz /patch/to/my/dir

You must log in to answer this question.

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