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