Can TAR both record symbolic links and the files/directories they reference?
The Tar command has an -h flag to follow symbolic links instead of recording the symbolic links. Is it possible to have both the symbo开发者_如何学运维lic links and what they point to in the archive? Can this be done automatically in one run of the TAR command?
Make sure both the symbolic link and the directory/file it points to are inside the tar content.
For example, assume you have a file work/mydir/myfile.txt
and a symbolic link work/mylink
which points to that file (with relative path):
work:
drwxrwxr-x. 2 ...... ...... 4096 May 16 11:54 mydir
lrwxrwxrwx. 1 ...... ...... 16 May 16 11:54 mylink -> mydir/myfile.txt
work/mydir:
-rw-rw-r--. 1 ...... ...... 0 May 16 11:54 myfile.txt
When you archive the work
directory, both the symbolic link and the file are put inside the tar archive:
$ tar cvf work.tar work/
work/
work/mylink
work/mydir/
work/mydir/myfile.txt
When that tar archive will be extracted, the file and the symbolic link will be created in the target directory.
精彩评论