$title = "Linking files and directories - ln"; $area = "Unix Support"; $metadata = "unix, commands, file, link, linking, ln, symbolic"; $pfloc = ""; require '/usr/local/wwwdocs/ucs/fragments/header.phtml'; require '/usr/local/wwwdocs/ucs/fragments/header-bc.phtml'; ?>
To link a file use the command:
ln filename1 linkname
Making a link to a file does not create another copy of the file; it makes a connection between the file and the linkname
To link files in the same directory:
ln notes circular
This creates a link circular to the file notes in the current working directory.
To make several links to a file in different directories:
ln part1.txt ../helpdata/sect1 /public/helpdoc/part1
This links part1.txt to ../helpdata/sect1 and /public/helpdoc/part1.
To use ln together with special pattern matching characters:
ln project/*.xdh $PWD
This links all the files with the extension ".xdh" in the sub-directory project to the current directory.
The value of the environment variable PWD is used instead of giving the path to the current directory.
Your files (and directories) may be located on several different file systems. To link files that are in different file systems you need to make a symbolic link.
To make a symbolic link use the command:
ln -s source linkname
To make a symbolic link from a file in one subdirectory to a file in another subdirectory:
ln -s reports/reportA publications/my_report
This makes a symbolic link between the file reportA in the subdirectory reports and the filename my_report in the publications subdirectory.
To make a symbolic link to a file in a subdirectory to your current working directory:
ln -s docs/editors/vi.ref .
This makes a symbolic link between the file vi.ref in the subdirectory docs/editors/ to the filename vi.ref in the current working directory.
To make a link to a file belonging to another user you need to:
Only the owner can change a file's access permissions.
To link one or more directories to another directory use the command:
ln -s directory_name(s) directory_name
The use of the -s option indicates that this is to be a symbolic link. As a user you are restricted to creating symbolic links between directories using the -s option.
To link a directory into your current directory:
ln -s $HOME/accounts/may
This links the directory $HOME/accounts/may into your current working directory. This link will have the same name may as the directory it points to.
To link several directories into a subdirectory:
ln -s $HOME/hyperhelp $HOME/metacard experimental
This links the directories $HOME/hyperhelp and $HOME/metacard into the subdirectory experimental.
There is a subtle difference between a "normal" directory and a directory created with a symbolic link to another directory.
What happens if you do a cd (change directory) to this type of directory? You are placed in the directory that the symbolic link points to.
Look at this example:
pwd(print the user's working directory)
/usr/home/john/tmp
ln -s $HOME/accounts/may fifth
(use a symbolic link named fifth that points to
the directory $HOME/accounts/may)
ls
fifth
cd fifth
(change directory to the new directory)
pwd
(print the working directory)
/usr/home/john/accounts/may
(the user is actually in the the directory that the
linked directory points to)
When the user does a cd (change directory) to the symbolically linked directory may in their current working directory, they change to the directory that this link points to, the directory /usr/home/john/accounts/may.
require '/usr/local/wwwdocs/ucs/fragments/footer.phtml'; ?>