シンボリックリンク先を固めるには -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

  • RT @__apf__: How to write a research paper: a guide for software engineers & practitioners. docs.google.com/presentation/d… /cc @inwyrd 6 months ago
  • RT @HayatoChiba: 昔、自然と対話しながら数学に打ち込んだら何かを悟れるのではと思いたち、専門書1つだけ持ってパワースポットで名高い奈良の山奥に1週間籠ったことがある。しかし泊まった民宿にドカベンが全巻揃っていたため、水島新司と対話しただけで1週間過ぎた。 それ… 6 months ago
  • RT @googlecloud: Ever wonder what underwater fiber optic internet cables look like? Look no further than this deep dive w/ @NatAndLo: https… 6 months ago
  • @ijin UTC+01:00 な時間帯で生活しています、、、 1 year ago
  • RT @mattcutts: Google's world-class Site Reliability Engineering team wrote a new book: amazon.com/Site-Reliabili… It's about managing produc… 1 year ago
%d bloggers like this: