One linux command (35) every day: ln command

Source: Internet
Author: User
Tags touch command
One linux command every day (35): ln command link: One linux command every day (1): ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html A linux command (35) every day: ln command link: A linux command (1) every day: ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html ; One linux command every day (3): pwd command http://www.2cto.com/os/201210/163462.html ; One linux command every day (4): mkdir command http://www.2cto.com/os/201210/163463.html ; One linux command every day (5): rm command http://www.2cto.com/os/201210/163662.html ; One linux command (6) every day: rmdir command http://www.2cto.com/os/201210/164017.html ; One linux command (7) every day: mv command http://www.2cto.com/os/201210/164247.html ; One linux command every day (8): cp command http://www.2cto.com/os/201210/164254.html ; One linux command every day (9): touch Command http://www.2cto.com/os/201211/165699.html ; One linux command every day (10): cat command http://www.2cto.com/os/201211/165989.html ; One linux command every day (11): nl command http://www.2cto.com/os/201211/165990.html One linux command every day (12): more command http://www.2cto.com/os/201211/165994.html One linux command every day (13): less command http://www.2cto.com/os/201211/165998.html One linux command every day (14): head Command http://www.2cto.com/os/201211/166191.html One linux command every day (15): tail command http://www.2cto.com/os/201211/168702.html One linux command every day (16): which command http://www.2cto.com/os/201211/168890.html A linux command (17) every day: whereis command http://www.2cto.com/os/201211/168893.html One linux command (18) every day: locate command http://www.2cto.com/os/201211/168895.html One linux command every day (19): find command overview http://www.2cto.com/os/201211/168897.html One linux command every day (20): find command exec http://www.2cto.com/os/201211/168901.html One linux command (21) every day: find command xargs http://www.2cto.com/os/201211/168903.html A linux command (22) every day: detailed description of the parameters of the find Command http://www.2cto.com/os/201211/168912.html A linux command (23) every day: Linux directory structure http://www.2cto.com/os/201211/170430.html One linux command every day (24): Linux file type and extension http://www.2cto.com/os/201211/170431.html One linux command every day (25): Explanation of linux file attributes http://www.2cto.com/os/201211/170434.html One linux command every day (26): use SecureCRT to upload and download files http://www.2cto.com/os/201211/172022.html One linux command every day (27): linux chmod command http://www.2cto.com/os/201211/172028.html One linux command every day (28): tar command http://www.2cto.com/os/201212/172641.html One linux command (29) every day: chgrp command http://www.2cto.com/os/201212/172983.html One linux command every day (30): chown command http://www.2cto.com/os/201212/173239.html A linux command (31) every day:/etc/group file details http://www.2cto.com/os/201212/174429.html One linux command (32) every day: gzip command http://www.2cto.com/os/201212/174431.html One linux command every day (33): df command http://www.2cto.com/os/201212/174434.html One linux command every day (34): du command http://www.2cto.com/os/201212/174701.html Ln is another important command in linux. its function is to create a non-same link for a file in another location. when we need to use the same file in different directories, we do not need to put a file that must be the same under each required Directory. we only need to put it in a fixed directory, put the file, and then use the ln command link in other directories to link it, without occupying disk space repeatedly. 1. command format: ln [parameter] [source file or directory] [target file or directory] 2. command function: there is a so-called link in the Linux file system www.2cto.com. we can regard it as the alias of the file, and the link can be divided into two types: hard link) with symbolic link, a hard link means that a file can have multiple names, while a soft link generates a special file, the content of this file points to another file. Hard links exist in the same file system, but soft links can span different file systems. Soft link: 1. soft link, which exists as a path. Similar to shortcuts in Windows 2. soft links can be cross-file systems, and hard links cannot be 3. soft links can be used to link a non-existent file name. 4. soft links can be hard links to directories: 1. hard links exist in the form of file copies. But it does not occupy the actual space. 2. hard links cannot be created for directories. 3. hard links can only be created in the same file system. Note the following two points: first, the ln command will keep the synchronization of each link file. that is to say, no matter which one you have changed, other files will change in the same way. www.2cto.com 2. ln links are divided into two types: soft links and hard links. soft links are the target file of the ln-s source file, it will only generate an image of a file at the position you selected, and will not occupy disk space. it will hard link the target file of the ln source file without the parameter-s, it will generate a file with the same size as the source file at the position you selected. both soft links and hard links keep the file changing synchronously. Ln commands are used to link files or directories. for example, if you specify more than two files or directories at the same time, and the final destination is an existing directory, all the previously specified files or directories will be copied to this directory. If multiple files or directories are specified at the same time and the destination is not an existing Directory, an error message is displayed. 3. command parameter: Required parameter:-B delete, overwrite the previously established link-d allow the superuser to create a hard link to the Directory-f force execution-I interaction mode, if the file exists, the system prompts you whether to overwrite-n. the symbolic link is considered as a general directory-s soft link (SYmbolic LinK)-v shows the detailed processing process. select the parameter-S "-S <字尾备份字符串> "Or" -- suffix = <字尾备份字符串> "-V"-V <备份方式> "Or" -- version-control = <备份方式> "-- Help displays help information -- version displays version information 4. use instance: instance 1: Create a soft link command for the File: ln-s log2013.log link2013 output: [root @ localhost test] # ll-rw-r -- 1 root bin 61 11-13 06:03 log2013.log [root @ localhost test] # ln-s log2013.log link2013 [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 16:01 link2013-> log2013.log-rw-r -- 1 root bin 61 11-13 06:03 log2013.log description: create a soft link link2013 for the log2013.log file. if log2013.log is lost, link2013 will fail instance 2: Create a hard link command for the File: ln log2013.log ln2013 output: [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 16:01 link2013-> log2013.log-rw-r -- 1 root bin 61 11-13 06:03 log2013.log [root @ localhost test] # ln log2013.log ln2013 [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 16:01 link2013-> log2013.log-rw-r -- 2 root bin 61 11-13 ln2013-rw-r -- r -- 2 root bin 61 11-13 log2013.log description: www.2cto.com creates a hard link ln2013 for log2013.log. log2013.log and ln2013 have the same attributes. Example 3: connect the two instances. after the link is complete, delete and recreate the original file. Command: output: [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 link2013-> log2013.log-rw-r -- 2 root bin 61 11-13 ln2013-rw-r -- r -- 2 root bin 61 11-13 log2013.log [root @ localhost test] # rm-rf log2013.log [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 link2013-> log2013.log- rw-r -- 1 root bin 61 11-13 ln2013 [root @ localhost test] # touch log2013.log [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 link2013-> log2013.log-rw-r -- 1 root bin 61 11-13 ln2013 --- xrw-r -- 1 root bin 302108 11-13 03 log2012.log-rw-r -- r -- 1 root 0 12-07 log2013.log [root @ localhost test] # vi log2013.log 2013-012013-022013-032013-042013-052013-062013-072013-082013-092013-102013--112013-12 [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 link2013-> log2013.log-rw-r -- 1 root bin 61 11-13 ln2013-rw-r -- r -- 1 root 96 12-07 log2013.log [root @ localhost test] # cat link2013 2013-012013-022013-032013-042013-052013-062013-072013-082013-092013--102013-112013-12 [root @ localhost test] # cat ln2013 hostnamebaidu = baidu. comhostnamesina = sina. comhostnames = true description: www.2cto.com 1. after the source file is deleted, it does not affect the hard link file. the soft link file keeps flashing in the centos system, prompting that the source file does not exist. after the source file is re-built, the soft link does not flash, indicating that the link is successful and the linked file system is found. after reconstruction, the hard link file is not affected by the source file, the content of the hard link file still retains the content of the source file before deletion, indicating that the hard link has expired instance 4: link the file to another directory with the same name command: ln log2013.log test3 output: [root @ localhost test] # ln log2013.log test3 [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 16:01 link2013-> log2013.log-rw-r -- 1 root bin 61 11-13 ln2013-rw-r -- r -- 2 root 96 12-07 log2013.log [root @ localhost test] # cd test3 [root @ localhost test3] # ll-rw-r -- r -- 2 root 96 12-07 log2013.log [root @ localhost test3] # vi log2013.log 2013-012013-022013-032013-042013-052013-062013-072013-082013-092013- 10 [root @ localhost test3] # ll-rw-r -- 2 root 80 12-07 16:36 log2013.log [root @ localhost test3] # cd .. [root @ localhost test] # lllrwxrwxrwx 1 root 11 12-07 link2013-> log2013.log-rw-r -- 1 root bin 61 11-13 ln2013-rw-r -- r -- 2 root 80 12-07 16:36 log2013.log [root @ localhost test] # description: create a hard link for log2013.log in the test3 Directory, modify the log2013.log file in the test3 directory, and synchronize it to the source file www.2cto.com instance 5: create a soft link command for the directory: ln-sv/opt/soft/test/test3/opt/soft/test/test5 output: [root @ localhost test] # lldrwxr-xr-x 2 root 4096 12-07 test3drwxr-xr-x 2 root 4096 12-07 test5 [root @ localhost test] # cd test5 [root @ localhost test5] # lllrwxrwxrwx 1 root 5 12-07 16:57 test3-> test3 [root @ localhost test5] # cd test3-bash: cd: test3: too many symbolic connections [root @ localhost test5] # [root @ localhost test5] # [root @ localhost test5] # lllrwxrwxrwx 1 root 5 12-07 test3-> test3 [root @ localhost test5] # rm-rf test3 [root @ localhost test5] # ll [root @ localhost test5] # ln-sv/opt/soft/test/test3/opt/soft /test/test5 create the symbolic link "/opt/soft/test/test3" pointing to "/opt/soft/test/test5/test3" [root @ localhost test5] # lllrwxrwxrwx 1 root 20 12-07 16: 59 test3->/opt/soft/test/test3 [root @ localhost test5] # [root @ localhost test5] # cd test3 [root @ localhost test3] # ll total 4-rw-r -- r -- 2 root 80 12-07 16:36 log2013.log [root @ localhost test3] # touch log2014.log [root @ localhost test3] # ll total 4-rw-r -- r -- 2 root root 80 12-07 log2013.log-rw-r -- 1 root 0 12-07 log2014.log [root @ localhost test3] # cd .. [root @ localhost test5] # cd .. note: 1. directory can only create soft links 2. the directory creation link must use an absolute path. the relative path cannot be created successfully. the following error occurs: too many layers of symbolic connections. 3. files modified in the target Directory of the link will be synchronized and changed in the source directory.
Related Article

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.