I did compress a directory to .tar.xz archive format with this command:

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

then,I tried to check health of created archive with following command:

tar --compare --file myArchive.tar.xz /path/to/my/dir

and I got this error lines :

tar: /path/to/my/dir: Not found in archive
tar: Exiting with  failure status due to previous error

I retried it but got same resault.what is the problem and how can I solve it?


If you really need to use absolute path names, then you should consider using -P for both your --create and --compare commands.

    -P, --absolute-names
        Don't strip leading slashes from file names when creating archives.


$ tar -cvPf a.tar /home/user/test_file
$ tar -dvPf a.tar /home/user/test_file

Or you could use -C, to change directory before the comparison.

    -C, --directory=DIR
        Change to DIR before performing any operations. This option is
        order-sensitive, i.e. it affects all options that follow.


tar -cvf a.tar /home/user/test_file
tar: Removing leading `/' from member names
tar -dvf a.tar -C/ home/user/test_file

The leading / may have been removed, therefore the pathname cannot be found in the archive.

When using the standard GNU tar and adding files /absolute/path/file.ext the leading / is removed and the file will be named absolute/path/file.ext inside the archive.

Usually this is written to stderr when archiving files, please check that output, it may look like in this example:

# tar -cvf test.tar /etc/passwd
tar: Removing leading `/' from member names
# tar -tf test.tar

Therefore please try running

tar --compare --file myArchive.tar.xz path/to/my/dir

leaving out the first character of the path if it is a /.


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.