ln:创建硬链接和软连接
简介ln命令(理解为英文单词link的缩写)用来为文件创件链接,连接类型分为硬连接和符号连接两种,默认的连接类型是硬连接。如果要创建符号连接必须使用"-s"选项。
说明:
ln命令(理解为英文单词link的缩写)用来为文件创件链接,连接类型分为硬连接和符号连接两种,默认的连接类型是硬连接。如果要创建符号连接必须使用”-s”选项。
格式:
ln [option] [source] [target]
ln [选项] [源文件或目录] [目标文件或目录]
常用参数说明:
-s:创建软连接(符号链接)
链接知识说明和示例
1、硬链接
- 硬链接是通过索引节点(Inode)来进行链接的。在Linux系统中所有的文件都有自己的一个独立的inode编号。硬链接生成的是一个普通的文件,目录不允许创建硬链接。硬链接的语法格式:ln source target
- 硬链接的文件是多个文件使用同一个inode编号
- 删除硬链接文件,源文件不受影响,删除源文件,硬链接文件也不受影响,所以这样可以作为备份
- 目录不可以创建硬链接
[root@localhost test]# ln test1.txt abc1.txt #创建硬链接
[root@localhost test]# ll -i
总用量 8
1410126 -rw-r--r--. 2 root root 4 5月 3 07:06 abc1.txt #是一个普通文件(-类型) inode:1410126与test1.txt一致
1410131 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir01
36737691 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir02
72060197 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir03
101621682 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir04
1410132 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir05
1410126 -rw-r--r--. 2 root root 4 5月 3 07:06 test1.txt
1410127 -rw-r--r--. 1 root root 0 5月 3 07:00 test2.txt
1410128 -rw-r--r--. 1 root root 0 5月 3 07:00 test3.txt
1410129 -rw-r--r--. 1 root root 0 5月 3 07:00 test4.txt
1410130 -rw-r--r--. 1 root root 0 5月 3 07:00 test5.txt
[root@localhost test]# cat test1.txt #查看test1.txt的内容
[root@localhost test]# echo 1 > test1.txt #写入1到test1.txt
[root@localhost test]# echo test1.txt
test1.txt
[root@localhost test]# cat abc1.txt #查看硬链接文件abc1.txt
1
[root@localhost test]# echo 2 >> abc1.txt #追加内容到硬链接文件中
[root@localhost test]# cat abc1.txt
1
2
[root@localhost test]# cat test1.txt #查看源文件内容
1
2
[root@localhost test]# rm -f abc1.txt #删除硬链接文件
[root@localhost test]# cat test1.txt #源文件不受影响
1
2
2、软链接
- 软链接又称为符号链接。语法格式:ln -s source target,目标文件不能事先存在,软链接生成的是一个符号链接文件(l类型)
- 可以把软链接理解成window系统的快捷方式
- 软链接类似于一个文本文件
- 删除了源文件,那么软链接一般都是白底红字显示
- 软链接和源文件的inode是不一样的
- 删掉还是可以使用rm
[root@localhost test]# ln -s test1.txt abc1.txt #创建软链接
[root@localhost test]# ll -i
总用量 4
1410133 lrwxrwxrwx. 1 root root 9 5月 3 07:14 abc1.txt -> test1.txt #软链接的类型(l类型) inode和源文件也不一致
1410131 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir01
36737691 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir02
72060197 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir03
101621682 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir04
1410132 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir05
1410126 -rw-r--r--. 1 root root 4 5月 3 07:06 test1.txt
1410127 -rw-r--r--. 1 root root 0 5月 3 07:00 test2.txt
1410128 -rw-r--r--. 1 root root 0 5月 3 07:00 test3.txt
1410129 -rw-r--r--. 1 root root 0 5月 3 07:00 test4.txt
1410130 -rw-r--r--. 1 root root 0 5月 3 07:00 test5.txt
[root@localhost test]# cat abc1.txt
1
2
[root@localhost test]# ln -s test2.txt dir01 #如果链接到存在的目录下,需要使用绝对路径,否查看会找不到对应的文件
[root@localhost test]# ll -i
总用量 4
1410133 lrwxrwxrwx. 1 root root 9 5月 3 07:14 abc1.txt -> test1.txt
1410131 drwxr-xr-x. 2 root root 22 5月 3 07:14 dir01
36737691 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir02
72060197 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir03
101621682 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir04
1410132 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir05
1410126 -rw-r--r--. 1 root root 4 5月 3 07:06 test1.txt
1410127 -rw-r--r--. 1 root root 0 5月 3 07:00 test2.txt
1410128 -rw-r--r--. 1 root root 0 5月 3 07:00 test3.txt
1410129 -rw-r--r--. 1 root root 0 5月 3 07:00 test4.txt
1410130 -rw-r--r--. 1 root root 0 5月 3 07:00 test5.txt
[root@localhost test]# ll -i dir01
总用量 0
1410134 lrwxrwxrwx. 1 root root 9 5月 3 07:14 test2.txt -> test2.txt #这里会进行提醒
[root@localhost test]# echo 3 >> test1.txt #追加数据到源文件
[root@localhost test]# cat test1.txt
1
2
3
[root@localhost test]# cat abc1.txt
1
2
3
[root@localhost test]# echo 4 >> abc1.txt #追加数据到目标文件
[root@localhost test]# cat abc1.txt
1
2
3
4
[root@localhost test]# cat test1.txt
1
2
3
4
[root@localhost test]# rm -f abc1.txt #删除
[root@localhost test]# ll -i
总用量 4
1410131 drwxr-xr-x. 2 root root 6 5月 3 07:16 dir01
36737691 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir02
72060197 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir03
101621682 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir04
1410132 drwxr-xr-x. 2 root root 6 5月 3 07:00 dir05
1410126 -rw-r--r--. 1 root root 8 5月 3 07:17 test1.txt
1410127 -rw-r--r--. 1 root root 0 5月 3 07:00 test2.txt
1410128 -rw-r--r--. 1 root root 0 5月 3 07:00 test3.txt
1410129 -rw-r--r--. 1 root root 0 5月 3 07:00 test4.txt
1410130 -rw-r--r--. 1 root root 0 5月 3 07:00 test5.txt
[root@localhost test]# touch test1.txt #重新新建源文件
[root@localhost test]# ln -s test1.txt abc1.txt #重新创建软链接
[root@localhost test]# rm -f test1.txt #删除源文件,那么软链接文件会提示
[root@localhost test]# ll
总用量 0
lrwxrwxrwx. 1 root root 9 5月 3 07:18 abc1.txt -> test1.txt
drwxr-xr-x. 2 root root 6 5月 3 07:16 dir01
drwxr-xr-x. 2 root root 6 5月 3 07:00 dir02
drwxr-xr-x. 2 root root 6 5月 3 07:00 dir03
drwxr-xr-x. 2 root root 6 5月 3 07:00 dir04
drwxr-xr-x. 2 root root 6 5月 3 07:00 dir05
-rw-r--r--. 1 root root 0 5月 3 07:00 test2.txt
-rw-r--r--. 1 root root 0 5月 3 07:00 test3.txt
-rw-r--r--. 1 root root 0 5月 3 07:00 test4.txt
-rw-r--r--. 1 root root 0 5月 3 07:00 test5.txt
提示
在软件的安装的时候,我们最好把每个版本分开安装,然后建立软链接指向固定的文件,这样方便其他人员查看和程序升级而不做任何修改。
如:
#如果我们安装了nginx
/apps/nginx1.19.1 #安装路径
ln -s /app/nginx1.19.1 /app/nginx #这样我们在每次升级软件后都建立软链接指向/app/nginx
《是妈妈是女儿》聚焦母女间未曾言明的爱意,以书信对话的形式呈现出各自的内心独白,表达彼此的牵挂。黄绮珊与希林娜依·高用跨越时空、打开心扉、深情对唱的形式,将天下母女爱的寄语化作心灵的倾诉。黄绮珊的每一句话,每一个字都演绎出了妈妈对女儿的爱,而希林依娜·高把女儿对妈妈的爱由不理解到理解再到感恩演绎得淋漓尽致。
如何通过查询语句来查询某个数据的排名,本文主要介绍MySql和MongoDB两种数据库的查询方式来进行排名。
GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
用一个已经创建的实例作为原型,通过复制该原型对象来创建一个和原型相同或相似的新对象。
快速生成表格
Electron页面跳转、浏览器打开链接和打开新窗口
Docker编译镜像出现:fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.12/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.2c4ac24e.tar.gz: No such file or directory问题
在使用Git的过程中,不想每次都输入用户名和密码去拉取代码,所以就需要保存这些信息,那么既然有保存了,就必须有清除功能。
在Mac电脑中,如何对Git的用户名和密码进行修改呢?起初不懂Mac,所以整了很久,本文将记录如何对这个进行操作,以便后期使用。