symbolic links function like shortcuts referencing another file. Symbolic links are much more flexible and can work over many different file systems
To set up a symbolic link, you use the ln command with the -s option and two arguments:
the name of the original file and the new, added filename. The ls operation lists both
filenames, but only one physical file will exist.
$ ln -s original-filename added-filename
In the next example, the today file is given the additional name weather. In this case,weather is another name for the today file.
$ ls
today
$ ln -s today weather
$ ls
today weather
You can give the same file several names by using the ln command on the same file many times. In the next example, the file today is assigned the names weather and weekend:
$ ln -s today weather
$ ln -s today weekend
$ ls
today weather weekend
If you list the full information about a symbolic link and its file, you will find the information displayed is different. In the next example, the user lists the full information for
both lunch and /home/george/veglist using the ls command with the -l option. The first character in the line specifies the file type. Symbolic links have their own file type, represented by an l. The file type for lunch is l, indicating it is a symbolic link, not an ordinary file. The number after the term group is the size of the file. Notice the sizes differ. The size of the lunch file is only 4 bytes. This is because lunch is only a symbolic link—a file that holds the pathname of another file—and a pathname takes up only a few bytes. It is not a direct hard link to the veglist file.
$ ls -l lunch /home/george/veglist
-rw-rw-r-- 1 george group 793 Feb 14 10:30 veglist
lrw-rw-r-- 1 chris group 4 Feb 14 10:30 lunch
To erase a file, you need to remove only its original name (and any hard links to it). If any symbolic links are left over, they will be unable to access the file. In this case, a symbolic
link will hold the pathname of a file that no longer exists.
No comments:
Post a Comment