Linux Soft Link File

Source: Internet
Author: User

Soft link file 1. What is a soft link file

A soft-link file in a Linux system is similar to a shortcut in a Windows system.

hypothetical scenario: For a file, it must be stored in the/root/111/directory, but there is another program that is using the a file and need to append log to a file, However, this program must be used in the/tmp/111 directory to use a file. So there are two ways to achieve this.

Mode 1: Give/root/111/a file, copy a copy, put it in the/tmp/111/directory for the program to use, after a period of time in the program, a text is modified, and then in the/tmp/111/directory, copy a file back to/root/111/to ensure consistency of a file.

Mode 2: Give/root/111/a file, make a soft link, link to the/tmp/111/directory, name or a, for the program to call. Because of the soft link is equivalent to a shortcut, so the a file under/root/111/will remain consistent regardless of how much content the program appends to a file in the/tmp/111/directory.

Obviously, Mode 2 is simpler than the mode 1 operation and consumes less disk space.

2. Understanding soft link files in the system
[Email protected] ~]# ls-l/binlrwxrwxrwx. 1 root root 7 May 23:52/bin-Usr/bin[[email protected] ~]#

650) this.width=650; "src=" Http://oqjg6c4c1.bkt.clouddn.com/201706091354_871.png "style=" border-style:none; "/>

/bin is a directory that actually resides in/usr/bin (directory is a special kind of file)

> System, most of the soft link files are in the lib64/directory

650) this.width=650; "src=" Http://oqjg6c4c1.bkt.clouddn.com/201706091358_185.png "style=" border-style:none; "/>

3. Create a soft link file

Format: ln-s source file Destination file

Soft links support both soft links to files and soft links to directories

ps: a convention that when creating a soft-link file, it is best to use an absolute path. If a relative path is used, there will be a problem if the source file is moved.

[[email protected] ~]# ls 2.txt  anaconda-ks.cfg.1[[email protected] ~ ]# ls /tmp/111  234  666     allinlinux                                                                    tmp222  345  allin2   systemd-private-0f4b60569c224727b1ec0153a8598630-vmtoolsd.service-qcx2tt  user1.txt[[email  Protected] ~]# ln -s /root/2.txt /tmp/2.txt[[email protected] ~]# ls  -l /tmp/Total dosage  0drwxrwxr--.  4 root   root   45 6 Month    8 21:20 111dRwxr-xr-x. 2 root   root    6 6 Month    8  20:11 222drwxrwxr-x. 3 allin1 allin1 26 6 Month    9 10:53  234lrwxrwxrwx. 1 root   root   11 6 Month    9  14:06 2.txt -> /root/2.txtdrwxr-xr-x. 3 root   root    26 6 Month    9 10:56 345drwxr-sr-x. 3 root   user1   26 6 Month    9 11:10 666drwxr-xr-x. 4 root    Root   40 6 Month    6 21:32 allin2drwxrwxrwx. 2 allin1  User1  19 6 Moon    8 14:58 allinlinuxdrwx------.  3 root    root   17 6 Month    8 14:15  Systemd-private-0f4b60569c224727b1ec0153a8598630-vmtoolsd.serviCe-qcx2ttdrwxr-xr-x. 4 root   root   28 6 Month    6  17:16 tmp-rw-rw-r--.  1 user1  user1   0 6 Month     9 13:03 user1.txt[[email protected] ~]#

650) this.width=650; "src=" Http://oqjg6c4c1.bkt.clouddn.com/201706091407_136.png "style=" border-style:none; "/>

4. Use of soft links in work

Scenario: There is a file that is stored on a partition that is nearly full of disk space, and has an important service that has been appending log to this file, and that the service can only be used on that file for that partition.

to better save the log, you can use a soft link to operate it to meet the needs of both disk space and complete storage of all logs.

  1. Copy the file to a disk partition with ample disk space and synchronize the good data ( You can use the Rsync tool to keep the file content synchronized, very fast, and in a flash.

  1. Use a soft link to link the file to the original disk partition, file name is consistent, for that An important service can function properly.

  1. Delete the original file and let the service continue to service to the soft link file.


This article is from the "Linux Road" blog, make sure to keep this source http://allin28.blog.51cto.com/12931477/1933861

Linux Soft Link File

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.