シンボリックリンク先を固めるには -h(–dereference) オプションが必要。


 /tmp/tartest$ mkdir a
 /tmp/tartest$ touch a/b
 /tmp/tartest$ ln -s a b
 /tmp/tartest$ ls -l
 total 4
 drwxr-xr-x 2 jsmith jsmith 4096 Nov 22 12:25 a
 lrwxrwxrwx 1 jsmith jsmith    1 Nov 22 12:25 b -> a


–dereference オプション無しの b1.tar と同 オプション有りの b2.tar を作る

 /tmp/tartest$ tar cvf b1.tar b
 /tmp/tartest$ tar cvfh b2.tar b

archive check

 /tmp/tartest$ tar tvf b1.tar
 lrwxrwxrwx jsmith/jsmith     0 2009-11-22 12:25 b -> a
 /tmp/tartest$ tar tvf b2.tar
 drwxr-xr-x jsmith/jsmith     0 2009-11-22 12:25 b/
 -rw-r--r-- jsmith/jsmith     0 2009-11-22 12:25 b/b


/tmp/tartest$ mkdir test
/tmp/tartest$ cd test/
/tmp/tartest/test$ tar xfv ../b1.tar
/tmp/tartest/test$ file b
b: broken symbolic link to `a'
/tmp/tartest/test$ ls -l
total 0
lrwxrwxrwx 1 jsmith jsmith 1 Nov 22 12:31 b -> a
/tmp/tartest/test$ unlink b
/tmp/tartest/test$ tar xfv ../b2.tar

GNU Tar のマニュアル“8.3.2 Symbolic Links“から

Normally, when tar archives a symbolic link, it writes a block to the archive naming the target of the link. In that way, the tar archive is a faithful record of the file system contents. ‘–dereference’ (‘-h’) is used with ‘–create’ (‘-c’), and causes tar to archive the files symbolic links point to, instead of the links themselves. When this option is used, when tar encounters a symbolic link, it will archive the linked-to file, instead of simply recording the presence of a symbolic link.

Tagged with: , ,
Posted in linux, tip

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: