3

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?

mmj
  • 99
  • 2
  • 11

2 Answers2

1

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
/etc/passwd
# tar -tf test.tar
etc/passwd

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 /.

thanasisp
  • 7,802
  • 2
  • 26
  • 39
Ned64
  • 8,486
  • 9
  • 48
  • 86
1

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.

Example:

$ tar -cvPf a.tar /home/user/test_file
/home/user/test_file
$ tar -dvPf a.tar /home/user/test_file
/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.

Example:

tar -cvf a.tar /home/user/test_file
tar: Removing leading `/' from member names
/home/user/test_file
tar -dvf a.tar -C/ home/user/test_file
home/user/test_file
thanasisp
  • 7,802
  • 2
  • 26
  • 39