Objective 6: Create and Change Hard and Symbolic Links
Often it is useful to have access to a file in multiple locations in a filesystem. To avoid creating multiple copies of the file, use a link. Links don’t take up very much space, as they only add a bit of metadata to the filesystem, so they’re much more efficient than using separate copies.
There are two types of links used on Linux:
- Symbolic links
A symbolic link is simply a pointer to another filename. When Linux opens a symbolic link, it reads the pointer and then finds the intended file that contains the actual data. Symbolic links can point to other filesystems, both local and remote, and they can point to directories. The ls -l command clearly lists them as links by displaying a special “l” (a lowercase L) in column one, and they have no file protections of their own (the actual file’s permissions are used instead).
A symbolic link can point to a filename that does not actually exist. Such a symbolic link is said to be broken or stale.
- Hard links
A hard link is not really a link at all; it is simply another directory entry for an existing file. The two directory entries have different names but point to the same inode and thus to the same actual data, ownership, permissions, and so on. In fact, when you delete a file, you are only removing a directory entry (in other words, one hard link to the file). As long as any directory entries remain, the file’s inode is not actually deleted. In fact, a file is not deleted until its ...