[RHEL7] tar doesn't follow the existing symlink with the same name as the directory that it is about to extract. First removes it and then proceeds extracting the directory from the archive.

Solution Verified - Updated -

Issue

  • On RHEL7, tar doesn't follow the existing symlink with the same name as the directory that it is about to extract. First removes it and then proceeds extracting the directory from the archive.

  • Creating two directories "/dir" and "/symlink":

[root@rhel7 /]# mkdir /dir /symlink
  • Archiving the directory "/symlink":
[root@rhel7 /]# tar cvf symlink.tar /symlink
tar: Removing leading `/' from member names
/symlink/
  • Removing the directory "/symlink":
[root@rhel7 /]# rm -rf /symlink
  • Creating the symblic link "/symlink" to the directory "/dir":
[root@rhel7 /]# ln -s /dir /symlink

[root@rhel7 /]# ll /dir /symlink
lrwxrwxrwx. 1 root root 4 Jul  5 12:16 /symlink -> /dir

/dir:
total 0
  • Extracting the directory "/symlink" from the archive:
[root@rhel7 /]# tar xvf symlink.tar 
symlink/
  • Now we can see that tar removes the symlink "/symlink" and replaces with the directory "/symlink" extracted from the archive:
[root@rhel7 /]# ll /dir /symlink
/dir:
total 0

/symlink:
total 0
  • On RHEL6, tar follows the existing symlink with the same name as the directory that it is about to extract.
[root@rhel6 /]# mkdir /dir /symlink

[root@rhel6 /]# tar cvf symlink.tar /symlink
tar: Removing leading `/' from member names
/symlink/

[root@rhel6 /]# rm -rf /symlink

[root@rhel6 /]# ln -s /dir /symlink

[root@rhel6 /]# ll /dir /symlink
lrwxrwxrwx. 1 root root    4 Jul  5 12:33 /symlink -> /dir

/dir:
total 0

[root@rhel6 /]# tar xvf symlink.tar 
symlink/

[root@rhel6 /]# ll /dir /symlink
lrwxrwxrwx. 1 root root    4 Jul  5 12:33 /symlink -> /dir

/dir:
total 0

Environment

  • Red Hat Enterprise Linux 7
  • tar - base version 1.26 from upstream
  • Red Hat Enterprise Linux 6
  • tar - base version 1.23 from upstream

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.