UNIX Environment Advanced Programming: Symbolic Links

Source: Internet
Author: User
Tags file system mkdir

A symbolic link is an indirect pointer to a file. He is different from the hard link in the previous section. The hard link points directly to the I node of the file. The reason for introducing symbolic links is to avoid some of the limitations of hard links.

Hard links often require links and files to reside on the same file system.

Only super users can create hard links to directories.

There is no file system restriction on symbolic links and what objects he points to. Any user can create a symbolic link to a directory. Symbolic links are typically used to move a file or this directory structure to another location on the system.

When you use a function that references a file by name, you should know whether the function handles symbolic links. That is, whether the function follows a symbolic link to a file that is in the chain section. If the function has the ability to handle symbolic links, its path name parameter refers to the file pointed to by the symbolic link. Otherwise, the path name parameter refers to the link itself. Rather than the file that the link points to. The following table lists the functions that are described in this chapter to handle symbolic links.

Function Do not follow symbolic links Follow Symbolic Links

The Mkdir,mkinfo,mknod and rmdir these functions are not listed in the table above. The reason for this is that when the pathname is a symbolic link, they all appear to be returned incorrectly. Some functions that take a file descriptor as parameters are also not listed in the table. The reason for this is that the processing of the link to the regal is performed by the function colleague who returned the file descriptor is open. Whether the chown follows the symbolic link depends on the implementation.

An exception to the table above is to call the Open function with both o_creat and O_EXCL. In this case, if the path name references a symbolic link, the Open function returns an error. and set the errno to Eexist. The intent of this approach is to block a security vulnerability. A process that makes it privileged will not be tricked into writing to a file that is not appropriate.


Using symbolic links may introduce loops in the file system. Most functions that find path names will return the value Eloop and errno when they occur in this case.

[Devis@gdmss unix_pro]$ mkdir foo  
[Devis@gdmss unix_pro]$ touch foo/a  
[Devis@gdmss unix_pro]$] ln-s. /foo foo/testdir   
[devis@gdmss unix_pro]$ ls-l foo
Total 0  
-rw-rw-r--1 devis devis 0 10-24 22:03 a  
lrwxrwxrwx 1 devis devis 6 10-24 22:03 testdir-> ... /foo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.