Symbolic link application in Linux

Source: Internet
Author: User

There are two different types of links, soft links and hard links, here we only discuss soft links. A soft link is actually a pointer to a file. You will find this soft link easy to use.


I. Using soft links to save multiple images of a file


Let's explain how the symbolic link is going. For example, in the/usr/local/admin/sales directory there is a document containing sales information, and everyone in the sales department wants to see the document. Instead of copying a copy of each directory, you can create a link to the file in each user's $home directory. This allows you to change only one source file when you need to change the file. The links in each sales $home directory can be any name and do not have to be consistent with the source file. If you have a lot of subdirectories and it takes time to get into these directories, links are also useful in this case. A link can be created for a very deep subdirectory under the $home directory. Also, for example, when installing an application, its logs are saved to the/usr/opt/app/log directory, and if you want to save it in another directory that you think is more convenient, you can create a link to that directory.

The general form of the command is:

ln [-S] source_path Target_path

The path can be either a directory or a file. Let's take a look at a few examples.


Two. Examples of symbolic links


If there are 4 0 sales and management users in the system, the sales user uses a sales application, and the administrative user uses a management application. What should I do as a system administrator? First delete all the. profile files in their respective $home directories. Two profile files are then created under the/usr/local/menus/directory, one is Sales.profile, and the other is Admin.profile, which provides the necessary environment for sales and management personnel and directs them into the appropriate application. Now I create a link to sales.profile in the $home directory of all the salespeople, creating a link to the Admin.profile file, respectively, under the $home directory of all the executives. Note that you do not have to create the appropriate file in the Target_path side of the command format above, and if such a file does not exist, the LN command will automatically create the file.

Here's what I did with sales people Matty.

$ cd/home/sales/matty

$ RM. Profile

$ ln-s/usr/local/menus/sales.profile. Profile

$ ls-al. Profile

$ lrwx rwx rwx 1 Sales admin 5567 Oct 3 05:40./profile->/usr/local/menus/sales.profile

(What you see may be slightly different from this).

This is all I have to do, and for the managers. And if you need to make any changes, simply change the profile of the sales and management staff without having to modify the 40 users individually.

Here is another example. The system I manage has a network monitor that writes logs in the/usr/opt/monitor/regstar directory, but all other logs are stored in the/var/adm/logs directory. This allows you to create a link to the original file in this directory to see all the logs in one place, without having to spend a lot of time separately into the respective directories.

Here is the link command used:

$ ln-s/usr/opt/monitor/regstar/reg.log/var/adm/logs/monitor.log

If the link is too many, you can delete some, but remember not to remove the source files.

Links can be created regardless of whether they are in the same file system. When creating a link, do not forget to set execution permissions in the original directory. Once the link is created, the linked directory will have permission 777 or rwx rwx rwx, but the actual permissions for the original file have not changed.

On a newly installed system, you typically do this by creating a link to the/tmp directory in the/var directory, because some applications think that the/var/tmp directory exists (but it does not actually exist), and some applications keep some temporary files in that directory. To keep all temporary files in one place, you can use the LN command to create a link to the/tmp directory under the/var directory.

$ pwd/var

$ ln-s/tmp/var/tmp

Now if I column the file in the/var directory, I'll be able to see the link I just created:

$ ls-l

$ lrwx rwx rwx 1 root root 5567 Sep 9 10:40 tmp->/tmp


Symbolic link application in Linux

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.