linux command - Links

This article is the work of some of the records usually less frequently used commands, add slowly accumulate, the equivalent of their own notes

Ln connection command

Two points to note:

First, ln command will keep every link file synchronization, that is, no matter what you change a place, other files are the same change;

Second, ln links and soft links and hard links are two kinds of soft links is ln -s ** **, it will only generate a mirror file in your selected position, does not take up disk space, hard links ln ** **, no argument -s, it will generate the same source file and a file size of your selected position, whether it is soft or hard links links, files are synchronized change.

ln --help
Usage: ln [option] ... [-T] link target name (first format)
or: ln [Options] ... target (second format)
or: ln [option] .. The target directory ... (third format)
or: ln [option] ... ... -t target directory (fourth format)
the In The 1st form, with Create A Link to the tARGET The name link_name.
the In 2nd form The, in Create A Link to the TARGET The Current Directory.
the in The 3rd and 4th Forms, Create links each to the TARGET in DIRECTORY.
the Create Hard links by default, symbolic links with --symbolic.
by default, each Where do you want (name of . new new Link) already exist Not Should
the When Creating Hard links, each the TARGET MUST Symbolic links exist.
CAN HOLD the arbitrary text; IF later resolved, IS Link A relative
Interpreted in Relation to ITS parent Directory.

Required parameters for the length of the options apply.
      --backup [= CONTROL] created for each destination file already exists in the backup file
  -b similar --backup, but does not accept any argument
  -d, -F, --directory create hard links to directories (only applies to super user)
  -f, --force forcibly remove any target file already exists
  -i, --interactive prompt to model types within the Remove Destinations
  -L, --logical make sure to dereference symbolic links targets that are
  -n, --no-make sure to dereference Treat link_name AS Normal File IF A
                                IT IS A to A symbolic Link Directory
  -P, --physical Hard links Directly to the make symbolic links
  -R & lt, --relative Create symbolic links relative to Link LOCATION
  -s, symbolic links INSTEAD of the make --symbolic Hard links
  -S, the override --suffix SUFFIX = Backup The usual suffix
  -t, --target-Directory = DIRECTORY The DIRECTORY in Which the Specify to Create
                                The links
  -T, --no-target-Treat link_name AS A Directory File Always Normal
  - v, --verbose Print File name of the each linked
      --help display this help and exit
      --version display version information and exit

Soft link ln -s

Specific usage is: ln -s source file destination 

如 :ln -s /opt/apache-tomcat-8/ ~/tomcat_8

View soft connection, ls -al command

Back tomcat_8 February 21 11:06 27 -> / opt /-Apache Tomcat. 8-/

Hard link ln

ln ~/log/reboot.sh ~/testfile.sh

Hard link to see there is no indication of a soft connection. The following is the difference

The difference between the two kinds of links:  

     There are two hard-linked files limit
   1), is not allowed to create a hard link directory;
   2), only to create links between files in the same system, but only the superuser have permission to establish a hard link.
       Hard linked files to read and write and delete operations when the same result, and soft links. But if we remove the hard-linked files source files, hard linked files still exist, but would like to retain some of the content.

          At this time, the system will "forget" it used to be hard linked files. And put him as a regular file.

         Then we can interpret it this way: hard-wired connection refers to by inode, its role is to allow a file path name with more effective, to achieve the role of accidentally deleted.

      The reason is because the corresponding inode file has more than one connection. To delete a connection does not only affect the inode itself and other

      Connection, only when the last connection is dropped, the connection data block and directory files will be released. The file will not actually be deleted.

         Note: Files saved to disk partition no matter what type it gave assign a number, called an inode number (Inode Index ie I node).          

     Soft links no more than two hard link limit, which is now more widely used, it has more flexibility, even across different machines, different network file link. But the disadvantage is that the soft link: because the link file contains the original file path information there, so when the original file is moved from one directory to other directories, and then access the link file, the system can not find it, and hard links do not have this defect how you want to move on how to move; it is also the system to allocate additional space for the establishment of a new index node and the path to save the original file.

Reference article: https://www.cnblogs.com/kex1n/p/5193826.html

Guess you like

Origin blog.csdn.net/liuhongbin2011net/article/details/87968542