Creating a Shortcut in a User Driectory

Can someone tell me how to create a shortcut within a users home directory to point to another location?

P.S- And is shortcut the correct terminology?

Thank you!

One correct way to communicatin is to say 'create a link'. There are two primary kinds of links, hard links and symbolic links. Directories are normally linked by symbolic links; files by hard links, but not always and YMMV. For example:

Your mail spool directory (located at /usr/spool/mail for example) is always full of big files and filling up your disk partition. You go out to ebay and purchase a 60GB drive for $100 bucks from You pay with Paypal and it ships the same day :slight_smile:

When it arrives, you have a spare slave port on one of your EIDE channels, so you power down and add the slave device and reboot. The drive is recognized by the BIOS (yippie!), so you run FDISK and create one big 60GB partition (because you get a lot of mail, mostly from spammers offering the fountain of youth and freedom from worries forever!!!).

You then create a directory (normally in the root partition) and then mount the new partition, call it (/usr/spool/supermaildisk). Then you shutdown your mail daemon and move all the mail in /usr/spool/mail to /usr/spool/supermaildisk. Then you remove the /usr/spool/mail directory and create a new symbolic link from /usr/spool/supermail to /usr/spool/mail.
You test to make sure you did not fat-finger any commands and make some goofy error, restart your mail daemon and 'poof!!', you just increased your mail spool directory to many GB.

Perhaps someone else will explain hard links and files, how to use symbolic links for library files, and other exciting fun with links :slight_smile:

[Edited by Neo on 03-19-2001 at 08:04 PM]

Anyone care to explain hard links?

A hard link is a link in the same filesystem with two i-node table entries pointing to the same physical contents (with the same i-node number because they point to the same data). If you want to see the effect of a link on the i-node table, display the i-node entry for a file in a directory, for example:

$ ls -i testfile
14253 testfile

Then, create a link to another filename and display the i-node entries again:

$ ln testfile test2
$ ls -i testfile test2

14253 testfile 14253 test2

As you can see, both file i-node numbers are the same. A directory listing of the two files shows that they have their own permissions and ownerships. The only thing indicating a link is the second column of the ls output, which shows a two for the number of links. Deleting a linked filename doesn't delete the file until there are no more links to it.

A symbolic link is another type of link that doesn't use the i-node entry for the link. The -s option to the ln command creates a symbolic link. For example, you can recreate the preceding example with a symbolic link:

$ ls -i bigfile
6253 bigfile
$ ln -s bigfile anotherfile
$ ls -i bigfile anotherfile

6253 bigfile 8358 anotherfile

As you can see, the i-node table entries are different. A directory listing shows the symbolic link as an arrow:

lrwxrwxrwx 1 root root 6 Sep 16:35 anotherfile -> bigfile
-rw-rw-r-- 1 root root 2 Sep 17:23 bigfile

The file permissions for a symbolic link are always set to lrwxrwxrwx. Permissions for access to the symbolic link name are determined by the permissions and ownership of the file it is symbolically linked to (bigfile in this case).

The difference between hard links and symbolic links is more than just i-node table entries.Unlike hard links (hard link is not allowed for directory and across different filesysems), symbolic links can be made to directories or across file systems with no restrictions. You can create symbolic links to files that don't exist yet(Opening this link will fail until a file by that name is created :wink: ), which you can't do with hard links. You can also follow symbolic links to find out what they point to, which is an almost impossible task with hard links. The kernel processes the two types of links differently, too.

Neo's example shows the importance and easiness of links.

PS: it's not just shortcuts; it's the standard way to link files and directories in unix. :slight_smile:

1 Like

Yes, I was hoping my casual example (with some humor tossed in) would send the message on how easy and important the concepts of linking in UNIX-like operating systems are to the user. The concept is much more powerful than 'shortcuts' and provides tremendous flexibility.

Super technical description from mib, BTW. The discusion on the difference between i-nodes for hard and sym links was interesting. If all the posts in the forum were this interesting, I would stop reading CNN :slight_smile: Thanks again!