ln -s accept wildcards?

Does ln -s accept wildcards? It doesn't seem like it is working when I use wildcards.

It does work, but you need to be somewhere else (not in the directory you use it from, since on its own their's no chance to give the link another name):

$ touch a b c
$ mkdir d && cd d
$ ln -s ../*
$ ll
total 0
drwxr-xr-x    2 scott     wheel            256 Sep 26 11:52 .
drwxr-xr-x    3 scott     wheel            256 Sep 26 11:52 ..
lrwxrwxrwx    1 scott     wheel              4 Sep 26 11:52 a -> ../a
lrwxrwxrwx    1 scott     wheel              4 Sep 26 11:52 b -> ../b
lrwxrwxrwx    1 scott     wheel              4 Sep 26 11:52 c -> ../c

Wildcards don't work inside the link. You can't create one link that will match several files.

The best you can do create multiple links like scottn demonstrates.

This is what I tried. Is there a problem with this?

#!/bin/bash
echo "Downloading Java"
yum -y install wget
wget http://download.oracle.com/otn-pub/java/jdk/6u27-b07/jre-6u27-linux-i586-rpm.bin
echo "Making executable"
chmod a+x jre*
echo "Installing java"
./jre*
cd /usr/lib/mozilla/plugins
echo "Making symlink so Firefox works"
ln -s /usr/java/jre*/lib/i386/libnpjp2.so

There is one if /usr/java/jre* doesn't exactly resolves into one single directory when the command is executed.

ln -s /usr/java/jre*/lib/i386/libnpjp2.so

Follow the logic for this.

If this resolves to one dir, you get ln -s /usr/java/jrewhatever/lib/i386/libnpjp2.so . It complains that you didn't give it a second filename to link to.

If this resolves to more than one, you're telling it to overwrite your other libnpjp2.so's with symlinks to the first one. Fortunately it won't as a safety feature.

I think what you want is:

ln -s /usr/java/default/lib/i386/libnpjp2.so /wherever/I/want/it/to/go.so

And you might only need to run it once, since /usr/java/default/ should point to the right place in any case.

Actually not. "ln -s" destination is an optional argument and defaults to the current directory if unspecified.

1 Like

I still don't understand what the problem is with using ln -s with wildcards :(. I've what you have said several times with no luck.

Well, the bottom line is that your command will fail with an error message if you have more than one version of JDK/JRE installed. If you have no error message, it should just work as expected.

Should you have more queries, please be more specific. Sentences like "It doesn't seem like it is working when I use wildcards." cannot lead anyone to understand what your problem is.

Wildcards don't do what you think they do.

A symlink is just a special kind of file whose contents are one literal filename. They're handled by the kernel, directly. When you open one, the kernel sees the contents and goes "hmm, this is a symlink to /usr/java/default/lib/i386/libnpjp2.s, I need to go open that instead". The filename is literal. A * won't be taken to be a wildcard, just a literal part of the name -- it is possible to create files and dirs named *...

Wildcards are handled by the shell, before you run ln. If multiple JRE's exist, your wildcards feed the whole list of things into ln, which isn't what you want -- it will try to create multiple links, like so:

$ mkdir e
$ touch a b c d
$ ln ../a ../b ../c ../d e # a b c d are links to be made, e is destination dir
$ ls -l e
total 0
lrwxrwxrwx 1 tyler users 4 Sep 28 08:59 a -> ../a
lrwxrwxrwx 1 tyler users 4 Sep 28 08:59 b -> ../b
lrwxrwxrwx 1 tyler users 4 Sep 28 08:59 c -> ../c
lrwxrwxrwx 1 tyler users 4 Sep 28 08:59 d -> ../d
$

When you force the link contents a literal * character, that won't help you because the kernel is not a shell, and won't expand * characters.

What, exactly did you try, and in what way did it not work?