[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
8.3.3 Hard Links
Normally, when tar
archives a hard link, it writes a
block to the archive naming the target of the link (a ‘1’ type
block). In that way, the actual file contents is stored in file only
once. For example, consider the following two files:
$ ls -l -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 one -rw-r--r-- 2 gray staff 4 2007-10-30 15:11 jeden
Here, ‘jeden’ is a link to ‘one’. When archiving this directory with a verbose level 2, you will get an output similar to the following:
$ tar cvvf ../archive.tar . drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./ -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden hrw-r--r-- gray/staff 0 2007-10-30 15:11 ./one link to ./jeden
The last line shows that, instead of storing two copies of the file,
tar
stored it only once, under the name ‘jeden’, and
stored file ‘one’ as a hard link to this file.
It may be important to know that all hard links to the given file are stored in the archive. For example, this may be necessary for exact reproduction of the file system. The following option does that:
- ‘--check-links’
- ‘-l’
Check the number of links dumped for each processed file. If this number does not match the total number of hard links for the file, print a warning message.
For example, trying to archive only file ‘jeden’ with this option produces the following diagnostics:
$ tar -c -f ../archive.tar -l jeden tar: Missing links to 'jeden'.
Although creating special records for hard links helps keep a faithful record of the file system contents and makes archives more compact, it may present some difficulties when extracting individual members from the archive. For example, trying to extract file ‘one’ from the archive created in previous examples produces, in the absense of file ‘jeden’:
$ tar xf archive.tar ./one tar: ./one: Cannot hard link to './jeden': No such file or directory tar: Error exit delayed from previous errors
The reason for this behavior is that tar
cannot seek back in
the archive to the previous member (in this case, ‘one’), to
extract it(19).
If you wish to avoid such problems at the cost of a bigger archive,
use the following option:
For example, trying this option on our two sample files, we get two copies in the archive, each of which can then be extracted independently of the other:
$ tar -c -vv -f ../archive.tar --hard-dereference . drwxr-xr-x gray/staff 0 2007-10-30 15:13 ./ -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./jeden -rw-r--r-- gray/staff 4 2007-10-30 15:11 ./one
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on November 1, 2013 using texi2html 5.0.