Linux LN Command Instance __linux

Source: Internet
Author: User
Tags syslog

For Example:

1. Create a connection to a file

[Root@a ~]# ln-s/home/kk/ss.sh ~ #如果不写目标地址, that is, in the current directory built link

[Root@a ~]# ls

Centos-base.repo.oldboy anaconda-ks.cfg install.log install.log.syslog ss.sh This command indicates that a link to the source file with the same name is created in the home directory to/home/kk/ss.sh Symbolic connection

[Root@a ~]# ln-s/home/kk/ss.sh ~/dd

[Root@a ~]# ls

Centos-base.repo.oldboy anaconda-ks.cfg DD Install.log install.log.syslog

This command indicates that a symbolic connection is established in the home directory that links to/home/kk/ss.sh and the name is DD (the premise is that there is no ABC this directory in the home directory)

2. Create a symbolic connection to a directory

[Root@a home]# ln-s/HOME/KK/HOME/ABC

[Root@a home]# ls

ABC Apache KK Oldboy

[Root@a home]# CD ABC

[Root@a abc]# ls

ss.sh

This command represents creating a symbolic connection in the/home directory that is linked to the/HOME/KK directory with the name ABC.

[Root@a home]# RM ABC

Rm:remove Symbolic link ' abc '? Y #删除所作目录链接时的提示

[Root@a ~]# ln-s/tmp ~/

[Root@a ~]# ls

Centos-base.repo.oldboy anaconda-ks.cfg Install.log install.log.syslog tmp

This command indicates that a symbolic connection with the same name as the source folder is created in the home directory

3. Create a hard connection to a file

[Root@a ~]# ln/home/kk/ss.sh ~/

[Root@a ~]# Ls-l

Total 60

-rw-r--r--1 root root 2239 Oct 09:30 centos-base.repo.oldboy

-RW-------1 root 1074 Nov 12:28 anaconda-ks.cfg

-rw-r--r--1 root root 26403 Nov 12:28 Install.log

-rw-r--r--1 root root 4378 Nov 12:28 install.log.syslog

-rw-r--r--2 root 14:31 Dec ss.sh

This command indicates that a link to the/home/kk/ss.sh hard link is created in the home directory with the same name as the source file, and the destination file is the same color as the original.

Ls–l also cannot show the path of the link

[Root@a ~]# ln/home/kk/ss.sh ~/ABC

[Root@a ~]# ls

Centos-base.repo.oldboy ABC anaconda-ks.cfg Install.log install.log.syslog

This command indicates the establishment of a link to/tmp/abc.txt in the home directory and a hard link with the name ABC (provided that there is no ABC of this directory in the home directory)

The existence of the ABC catalogue

[Root@a ~]# mkdir ABC

[Root@a ~]# ls

Centos-base.repo.oldboy ABC anaconda-ks.cfg install.log install.log.syslog

[Root@a ~]# ln/home/kk/ss.sh ~/abc #做硬链接

[Root@a ~]# ls

Centos-base.repo.oldboy ABC anaconda-ks.cfg install.log install.log.syslog

[Root@a ~]# CD ABC

[Root@a abc]# ls

ss.sh

 

source file is directory can not do hard link

[Root@a ~]# Ln/home/kk ~/ABC

ln: '/home/kk ': Hard link not allowed for directory

4. Parameter-V Usage

Hard Links:

[Root@a home]# ln-v/home/kk/ss.sh/home #加上参数v后,

Create hard link '/home/ss.sh ' to '/home/kk/ss.sh ' #会用文字显示源文件到目标的链接

[Root@a home]# ls

Apache KK Oldboy ss.sh

[Root@a home]# ln-vs/home/kk/ss.sh/home #创建名子相同的软链接

Create symbolic link '/home/ss.sh ' to '/home/kk/ss.sh ' #会用文字显示源文件到目标的链接

ln:creating Symbolic link '/home/ss.sh ' to '/home/kk/ss.sh ': File exists #同时也出现了己存在提示

Soft Links

[Root@a home]# ln-vs/home/kk/ss.sh/home/dd #加上参数v后的软链接

Create symbolic link '/home/dd ' to '/home/kk/ss.sh ' #会用文字显示源文件到目标的链接

[Root@a home]# ls

Apache DD KK Oldboy ss.sh

Green soft links, the same as the original color is a hard link

the use of 5.-f

[Root@a home]# ls

Apache DD KK Oldboy ss.sh #dd is a soft link exists; ss.sh is a hard link.

[Root@a home]# ln-s-f/home/kk/ss.sh/home #创建/home/kk/ss.sh Soft links

[Root@a home]# ls

Apache DD KK Oldboy ss.sh #上面加了f参数, ss.sh is now a soft link

[Root@a home]# ln/home/kk/ss.sh/home/dd #创建/home/kk/ss.sh hard link, the name is also DD

ln:creating hard link '/home/dd ' to '/home/kk/ss.sh ': File exists #提示出现了

[Root@a home]# ln-f/home/kk/ss.sh/home/dd #加上f参数后, no hint.

[Root@a home]# ls

Apache DD KK Oldboy ss.sh #dd变成链接了,

The main process of-F: First delete the soft link dd with the same name, and then create the hard link dd

usage of 6.-d and b

[Root@a home]# ln/home/kk/home/dd #创建硬链接不允许

ln: '/home/kk ': Hard link not allowed for directory #不允许对目录创建硬链接

[Root@a home]# ln-f/home/kk/home/dd #加上-D parameter

ln:creating hard link '/home/dd ' to '/home/kk ': Operation not permitted #为什么还是不行呀.

The use of 7.-i

[Root@a home]# ln-s/home/kk/ss.sh #创建软链接

[root@a home]# ls #查看

Apache KK Oldboy ss.sh

[Root@a home]# ln-fi/home/kk/ss.sh #加上-F parameter deletes the same name plus-I argument-prompts before deleting

Ln:replace './ss.sh '? #提示

 

[Root@a home]# ln-fi/home/kk/ss.sh

Ln:replace './ss.sh '? n #我选择了n

[root@a home]# ls #查看

Apache KK Oldboy ss.sh #还存在

[Root@a home]# ln-fb/home/kk/ss.sh #加上参数b

[root@a home]# ls #查看

apache  kk  oldboy  ss.sh  ss.sh~     #之前存在的软链接被更名备份了, and then create a hard link with the same name

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.