ln, link -- make file system links
ln [-fhinsv] originalFile [newlink]
ln [-fhinsv] originalFile ... link_dir
link originalFile newlink
Creates a new directory entry (newlink) with the same modes as the original file.
Used to create multiple appearances of a file.
newlink points to the originalFile.
-i |
The types of links are: hard links and symbolic links.
originalFile that was added when the originalFile was created.originalFile was created are indistinguishable.ls -l hardlinkfiles* includes a link count of the number of directory entries which point to a file.
Changing the mode (permissions), stored in the inode, effects all entries.> ./reptpgm > origfile > ls -l origfile -rw-r--r-- 1 dgerman devgrp 0 Apr 1 13:50 origfile > ln origfile hardLink > ls -l orig* hard* -rw-r--r-- 2 dgerman devgrp 0 Apr 1 13:50 origfile -rw-r--r-- 2 dgerman devgrp 0 Apr 1 13:50 hardlink
originalFile directory entry or those created using ln does not delete the file until the last entry is removed.
( i.e. When the link count is reduced to 0)ln will report "Cross-device link"-s to create a symbolic directory link.
originalFile.originalFile is used when an open is performed on the symbolic link.ls -l displays an l as the first character, unique date fields (these are part of the directory entry, not the file) and an "arrow" ( -> ) pointing to the originalFile.
additional date information is available using stat The link count for both entries is 1.> ls -l * lrwxr-xr-x 1 dgerman devgrp 6 Apr 1 14:08 symlink -> target -rw-r--r-- 1 dgerman devgrp 0 Apr 1 14:06 target
symlink is size 6 since t,a,r,g,e,t is 6 characters.newlink !
There is no information in the target file that a symbolic link to it exists!
Unfortunately, removing the target file with out removing the synbolic link, causes accesses to the symbolic
link to report: No such file or directory!
stat on a symbolic link will return the target file
lstat must be done to obtain information about the newlink.
readlink is used to read the contents of a symbolic link.
> ln -s "/Volumes/BACKUPS/notTimeMachine" mirror3 > ls -l mirror3 lrwxr-xr-x dgerman 501 33 Sep7 22:22 mirror3 -> /Volumes/BACKUPS/notTimeMachine > ls -ld mirror3 lrwxr-xr-x dgerman 501 33 Sep7 22:22 mirror3 -> /Volumes/BACKUPS/notTimeMachine > stat mirror3 234881028731036 lrwxr-xr-x dgerman (501) 0 33 "Sep7 22:22:34 2008" "Sep7 22:22:34 2008" "Sep7 22:22:34 2008" "Sep7 22:22:34 2008" 4096 8 0 mirror3 > readlink mirror3 /Volumes/BACKUPS/notTimeMachine > cd mirror3 mirror3 >
Symbolic links may span file systems and may refer to directories.
Given one or two arguments, ln creates a hard link to an existing originalFile.
> cd ~
> ln ../yourdirectory/notes Creates a hard link in my home directory to your file notes. > ls -log docu ../yourdirectory/notes
-rwxr-xr-x 2 20 Jan 5 11:43 notes
-rwxr-xr-x 2 20 Jan 5 11:43 notes
Given more than two arguments, ln makes links in link_dir to all the
named source files. The links made will have the same name as the files being linked to.
link takes exactly two filenames and creates a hard link. No options may be supplied.
SEE lstat,readlink,stat,symlink,symlink(7)
BUG: ln -s nofile newlink does not display a message if nofile does not exist and return code is set to 0!
Perhaps alias ln='ln
BSD December 30, 1993 BSD