Front | Info | Lists | Newsfeeds | Study Guide | What is BSD? |
|
This is the BSDA Study Guide Book written via a wiki collaboration. This is a work in progress. You may contribute to or discuss this specific page at http://bsdwiki.reedmedia.net/wiki/Create_and_view_symbolic_or_hard_links.html. Create and view symbolic or hard linksConceptKnow the difference between symbolic and hard links as well as how to create, view and remove both types of links. In addition, be able to temporarily resolve a low disk space issue using a symbolic link. IntroductionA link allows several filenames to refer to a single file on disk. There are two types of links: hard links and symbolic links. A hard link associates two or more filenames with the same inode. Thus hard links allow different directory entries to refer to the same disk data blocks. Symbolic, or soft links as they are sometimes known as, are pointer files that name another file elsewhere in the file system. As symbolic links point to another pathname in the filesystem they can span physical devices, as they point to a pathname not actual disk location of the file. Both hard and symbolic links are created with the ln command. Changes made to either the hard linked file or the original will effect both of them since they share the same disk data blocks. ls marks symbolic links with an 'l'. Using the '-i' option to ls will list the inodes of each file which will identify the hard linked files:
rm will remove both hard and symbolic links, however if the symbolic link is deleted it does not affect the file referenced by the link. Similarly, in the above example deleting index will not affect hardlink even though it is the same file. The stat(1) utility displays file status. Using stat -F filename will highlight symbolic links with a trailing '@' and show the file to which it is linked:
The power of stat lies in its ability to format the output, as illustrated in the example taken from the man page:
ExamplesCreate an entry in the current directory called hardlink with the same inode as index:
Create a symbolic link to index in the current directory:
Practice ExercisesMore informationln(1), ls(1), rm(1), stat(1)
|