Links Hard links:

advertisement
Links
(hard and symbolic)
Links allow directories and files to reside in two places on your filesystem at the same time.
Hard links: Link files or directories on the same device. (a file with two filenames!)
Example:
ln fileA /directoryName/fileB
The files fileA and fileB are now mirror copy files (filenames) —but only one copy of
the actual file resides on the drive! Changes made to one of the files (filenames) are
reflected in the other. Either of the filenames may be deleted, but its linked filename
—and the actual file on disk remains intact. Only when all of the linked filenames for a file
are deleted is the actual file on disk deleted.
Important: In the above example, fileB should not exist before the link is preformed.
Linking directories:
Example:
ln /dirA /dirB
The directory /dirB is now a mirror of the directory /dirA.
Important: In the above example, dirB should not exist before the link is preformed.
To remove a directory, it must be unlinked.
Example: unlink /dirB
Symbolic Links: Link files and directories that can reside on different physical devices.
Example:
ln -s /home/mine /media/sdb/myhome
The link-directory (shortcut) /media/sdb/myhome will appear as a mirror of the directory
/home/mine that it points to.
If the –F option is used with the ls command (example: ls –FAC /media/sdb ) the
directory myhome will appear with an @ sign prefix to show it is a symbolic link. The
directory may also appear on a special color –usually light cyan.
If the –l option is used to get a ‘long listing’ (example: ls –hal /media/sdb ) the directory
myhome will appear with a trailing arrow -> followed by the path to the directory it points
to: /home/mine.
Important: /media/sdb/myhome should not exist before the link is preformed.
Use full path names when creating symbolic links. If the directory /home/mine is removed,
then /usr/media/myhome will become an orphan and will no longer be accessible.
To remove the symbolic link, the entire linked directory should be removed.
Example: rm /media/sdb/myhome
WARNING! The command: rm /media/sdb/myhome/*
removes all the files in the directory it points to: /home/mine. It does not remove the link.
Download