What are you attempting to do?
Think of a link as a cp
command. Maybe that will help:
# Copies the 'svnadmin' command from /opt/svn/bin to /usr/local/bin
$ cp /opt/svn/bin/svnadmin /usr/local/bin
# Links the 'svnadmin' command from /opt/svn/bin to /usr/local/bin
$ ln -s /opt/svn/bin/svnadmin /usr/local/bin
Note that the ln
and cp
command have the same order of files.
In your command, you're linking whatever location/to/directory/
to $D/test2
over and over again.
Also, -maxdepth 0
won't be in the first level of the directory.
I use ln
when I install new software, and the binary commands are in some other directory. Instead of building on $PATH
to include all of these extra directories, I symbolically link them to /usr/local/bin
:
$ cd /usr/share/apache-ant/bin
$ for file in *
> do
> [[ -f $file ]] || continue
> ln -s $PWD/$file /usr/local/bin/$file
> done
Note that the link simply copies the entire reference for the first file to the link. I want to make sure that this link works everywhere, so I prefix that $PWD
in front of it. This way, my links look like this:
$ ls -l ant
lrwxr-xr-x 1 root wheel 29 Sep 3 2014 ant -> /usr/share/apache-ant/bin/ant