Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install symbolic links with coreutils install

I built a library and I want to install the library to /usr/local/lib using coreutils install. The result of the build looks as follows:

libfoo.so -> libfoo.so.1
libfoo.so.1 -> libfoo.so.1.1
libfoo.so.1.1

I want to retain the symbolic links and install the files as is to /usr/local/lib. However, if I run

install libfoo* /usr/local/lib

the symbolic links are resolved and /usr/local/lib looks as follows:

libfoo.so
libfoo.so.1
libfoo.so.1.1

In other words, these are all real files and no symbolic links.

The manpage of install does not contain any information about resolving symbolic links. How can I install symbolic links?

like image 582
morxa Avatar asked Feb 22 '16 18:02

morxa


People also ask

Is soft link same as symbolic link?

A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias. Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system.

How do you create symbolic link in the Linux file system?

Ln Command to Create Symbolic Links By default, the ln command creates a hard link. Use the -s option to create a soft (symbolic) link. The -f option will force the command to overwrite a file that already exists. Source is the file or directory being linked to.


2 Answers

Please be note that the install utility always dereferences symlinks.

Please see my question here.

To copy files while preserving everything (symlinks, hard links, mode, etc) you can use cp -a

You can also use tar:

tar c -C source_dir file1 ... fileN | tar xv -C dest_dir

Be aware that both cp -a and tar will preserve user and group and that those files must probably be owned by root:root at the destination. You may have to add a chown afterwards.

like image 116
Robert Hu Avatar answered Oct 18 '22 19:10

Robert Hu


I wondered about this too. After looking at the source code it would appear that install is pretty aggressive about resolving links at install time. Here are some of the defaults it passes to cp; the relevant ones don't get overridden later.

cp_option_init (struct cp_options *x)
{
  cp_options_default (x);
  x->copy_as_regular = true;
  x->reflink_mode = REFLINK_NEVER;
  x->dereference = DEREF_ALWAYS;
  x->hard_link = false;
  x->preserve_links = false;
  x->preserve_mode = false;
  x->symbolic_link = false;
(...)

The workaround would be to use cp + chmod.

like image 30
Robert Calhoun Avatar answered Oct 18 '22 18:10

Robert Calhoun