The FreeBSD Diary |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
Creating a symbolic link
|
This article shows you how to create a symbolic link. You might also want to see Linking to other directories with Apache. |
What is a symbolic link?
|
A symbolic link is a way of saving disk space when the same file structure must exist
in two places. It's also a way of creating a short cut to another place. These
shortcuts are used quite often on ftp servers. For example, if you look at your
typical FreeBSD ftp server, you might see something like this:ftp> cd /pub/FreeBSD 250 CWD command successful. ftp> ls 3* 227 Entering Passive Mode (203,97,33,7,193,160) 150 Opening ASCII mode data connection for /bin/ls. lrwxrwxrwx 1 0 1 25 May 9 22:29 3.1-RELEASE -> releases/i386/3.1-RELEASE lrwxrwxrwx 1 0 1 25 May 9 22:29 3.1-STABLE -> releases/i386/3.1-RELEASE lrwxrwxrwx 1 0 1 25 May 18 10:03 3.2-RELEASE -> releases/i386/3.2-RELEASE 226 Transfer complete. You can see that the releases actually exist within a subdirectory. In case, the links are relative to the current path. |
/home
|
You should see man
ln for full details. But here are a few practical examples. The following demonstrates that /home is a shortcut for /usr/home. # cd / # ls -ld home lrwxr-xr-x 1 root wheel 9 Jun 20 19:28 home -> /usr/home This link could be created with: # ln -s /usr/home /home In this case the links are absolute, not relative as in the ftp server example. |
Files
|
You can also create a symbolic link with a file. I'll show you some FreeBSD
examples from /dev and in /etc.# cd /dev # ls -lt | grep ">" lrwxr-xr-x 1 root wheel 10 Jul 5 11:47 vga -> /dev/ttyv0 lrwxr-xr-x 1 root wheel 12 Jun 20 19:15 log -> /var/run/log lrwxrwxr-x 1 root wheel 5 Jun 20 19:05 wcd0c -> acd0c lrwxrwxr-x 1 root wheel 6 Jun 20 19:05 rwcd0c -> racd0c lrwxrwxr-x 1 root wheel 6 Jun 20 19:05 rwcd0a -> racd0a lrwxrwxr-x 1 root wheel 5 Jun 20 19:05 wcd0a -> acd0a # cd /etc # ls -lt | grep ">" lrwxrwxrwx 1 root wheel 23 Jun 20 18:58 termcap -> /usr/share/misc/termcap lrwxrwxrwx 1 root wheel 13 Jun 20 18:58 rmt -> /usr/sbin/rmt To create a symbolic link in your home directory from such as the termcap link above, you could do this: # ln -s /usr/share/misc/termcap /etc/termcap |