Linode Library Home
Linode Library RSS Feed
Home :: Linux Tools :: Common Commands
Print View View Source

Create File System Links with ln

Published: by

The ln command creates "meta objects" in the file system that link to other objects located on the file system. Links may point to files, directories, or other links. Although improper use can lead to disorganization and confusion, links are useful for providing access to files and file system organization.

Contents

File System Linking

The ln Command

Consider the following command:

ln -s /srv/www/example.com

This creates a link, named "example.com" in the current directory to the directory or file located at /srv/www/example.com. If you want to specify a different name for the link object, append that name to the end of the above command as in the following:

ln -s /srv/www/example.com example

If you want to create a symbolic link in a directory other than your current directory, you can specify a full path in the final argument of the command:

ln -s /srv/www/example.com/public_html /home/squire/public/example

Security Concerns

Symbolic links can be moved, renamed, and removed at any time. When a link is created with a relative path specified and the link is later moved, the target of the link is also expected to move. If it doesn't, the link will point to an object that doesn't exist. This can lead to potential security flaws if a symbolic link is copied or transferred to a different system, or if the link object is moved and the "target" is replaced with malicious content. Be wary of potential issues that this may create.

Examples