6

How to create an archive containing links and the linked files. I have some shared libraries of which I want to create an archive. This is what I tried

mkdir dest #abc.so is a link file which points to abc.so.1 #abc.so.1 is a link file which points to abc.so.1.1 #abc.so.1.1 is the actual file cp /usr/local/lib/abc.so* dest/ tar -czvf dest.tar.gz -C dest/ . 

But the resulting dest.tar.gz file lists links and linked files with same size and no l file type for links in the output of tar -tvf dest.tar.gz.

0

1 Answer 1

11

The cp operation does not preserve the symbolic links. The tar archiver archives symbolic links without issue.

You most likely want to use cp with its -P option. This is a standard option.

cp -P /usr/local/lib/abc.so* dest/ 

You could also use rsync:

rsync -a /usr/local/lib/abc.so* dest/ 

The -a option (--archive) is a shortcut for -rlptgoD, and it's the -l option in particular that preserves the symbolic links as links (the other options preserve ownership, timestamps, and other meta data of the files, etc.)

GNU's coreutils implementation of cp also has an -a option that will try to preserve as much as possible of metadata etc. You would be able to use cp -a in place of cp -P to copy symbolic links, provided that the system uses coreutils.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.