开发者

Can TAR both record symbolic links and the files/directories they reference?

开发者 https://www.devze.com 2023-03-31 00:52 出处:网络
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?Ca

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号