Create links to (aliases for) files (POSIX)
ln [-f|-i] [-s] [-v] source_file target_file ln [-f|-i] [-s] [-v] source_file... target_dir
The ln utility has two syntax forms, as follows:
First syntax form:
Second syntax form:
The destination path for each source_file is the same as its basename (final path component). For example:
ln dir/dir/myfile /existingdirwill create /existingdir/myfile as a link to dir/dir/myfile.
This second syntax form is assumed when either the destination names an existing directory, or when more than one source file is specified.
If the destination path exists and you have write permission for the existing destination file, or if -f was specified, ln will unlink the destination, then create the new link.
If you don't have write permission for an existing directory path, and -f is not specified, and if the standard input is a tty, ln will prompt you for confirmation prior to unlinking the existing file. If standard input isn't a tty, ln will write a diagnostic message to standard error, and go on to the next source_file without unlinking the destination file.
To create the new link, or replace a file with a link, you will need write permissions for the directory in which the new link is going to reside. Note that root will always have this permission regardless of the file permission settings.
Hard links are limited to within the same filesystem as the original file and aren't permitted on directories. With symbolic links, however, you can link any pathname to a file. A symbolic link is a special file that has the destination pathname as its data. For more information, see the section on symbolic links in QNX System Architecture.
Create a link to /home/curious/monkey called gorilla in the /home/george directory:
ln /home/curious/monkey /home/george/gorilla
Create a symbolic link to the directory //1/home/fred called //2/home/barney:
ln -s //1/home/fred //2/home/barney
If a destination path exists, and ln is interrupted before ending, the destination path may have been removed without the new link having been created. |
When creating a symbolic link, ln does not check that the source_file named actually exists, or even that it is a valid pathname. If the file does not exist or if the source_file is not a valid pathname, it will fail when any process attempts to access that link. |