ln(1) — Commands
OSF — Environment_Note_Added
NAME
ln − Links files
SYNOPSIS
ln [-fs] source_file target_file
ln [-fs] source_file ... target_directory
ln -s [-f] source_file
The ln command links a single file source_file to file target_file (in the current directory), links one or more files to the same filename(s) in another existing directory (target_directory), or creates a link to the last component in source_file.
FLAGS
-fForces removal of existing target pathnames to allow specified links.
-sCreates symbolic links.
DESCRIPTION
By default, ln makes hard links; the -s flag makes symbolic links.
A symbolic link contains the name of the file to which it is linked. The referenced file is used when an open() operation is performed on the link. A stat() call on a symbolic link returns the linked-to file; an lstat() call must be done to obtain information about the link. The readlink() call can be used to read the contents of a symbolic link. Symbolic links can span file systems and can refer to directories.
EXAMPLES
1.To create a link (also called an alias) to a file, enter:
ln chap1 intro
This links chap1 to the new name intro. If intro does not already exist, the filename is created. If intro does exist and permissions allow, the file is replaced by a link to chap1. To force the link even if intro exists and permissions do not allow it to be overwritten, enter:
ln -f chap1 intro
Now chap1 and intro are two filenames that refer to the same file. Any changes made to one also appear in the other. If one name is deleted with del or rm, the file is not actually deleted, but remains under the other name.
2.To link a file to the same name in another directory, enter:
ln index manual
This links index to the new name manual/index. Note that intro in Example 1 is the name of a file; manual in Example 2 is a directory that already exists.
3.To link several files to names in another directory, enter:
ln chap2 jim/chap3 /u/manual
This links chap2 to the new name /u/manual/chap2 and jim/chap3 to /u/manual/chap3.
4.To use ln with pattern-matching characters, enter:
ln manual/∗ .
This links all files in the directory manual into the current directory (.), giving them the same names they have in manual. Note that you must type a space between the ∗ (asterisk) and the . (dot).
5.To create a link to the final component of a pathname, enter:
ln -s /a/b/c/d/e
This creates a link, \e, in the current directory to the file /a/b/c/d/e.
NOTES
You cannot link files across file systems without using the -s flag.
ENVIRONMENT NOTES
This section describes system features that are not generic to OSF/1 but that are provided in this OSF/1 implementation.
SVID Conformance
For DEC OSF/1, the behavior of ln was modified to bring it into conformance with SVID-2 and XPG standards. The behavior described here applies both by default and for the SVID-2 habitat.
The ln command includes the -f option. If the target filename exists, is not a directory, and does not have write permission, three possible conditions can exist, with each condition producing a different behavior:
•If ln is not being run interactively, the command attempts to silently unlink the target file and link the source file to it.
•If ln is being run interactively and the command line does not include the -f option, the command prompts the user for permission to unlink the target file. The command compares the user response to the system defined values for YESSTR and NOSTR. If the user response matches the value for YESSTR, the command attempts to unlink the target file and link the source file to it. If the user response matches NOSTR, the command aborts.
•If ln is being run interactively and the command line includes the -f option, the command attempts to silently unlink the target file and link the source file to it.
RELATED INFORMATION
Commands: cp(1), mv(1), rm(1).
Functions: chmod(2), link(2), readlink(2), symlink(2), unlink(2).