Linux链接命令的实例详解

 更新时间:2017年08月30日 11:23:42   投稿:lqh  
这篇文章主要介绍了Linux链接命令的实例详解的相关资料,希望通过本文大家能掌握Linux链接命令的使用方法,需要的朋友可以参考下

Linux链接命令的实例详解

一 语法

ln -s [源文件] [目标文件]
命令英文含义:link
功能描述:生成链接文件
选项:-s 创建软链接 

二 硬链接特征

原文件和硬链接文件删除其中任何一个都没问题。

三 硬链接实战

[root@localhost ~]# cd test
[root@localhost test]# ls
bcd
[root@localhost test]# ln bcd abc.hard
[root@localhost test]# ll
total 0
-rw-r--r--.2 root root 0Jul1219:31 abc.hard
-rw-r--r--.2 root root 0Jul1219:31 bcd
[root@localhost test]# vi bcd
[root@localhost test]# cat abc.hard 
qwer 
[root@localhost test]# echo "dfd">> abc.hard 
[root@localhost test]# cat bcd 
qwer 
dfd
[root@localhost test]# ls -i
67170460 abc.hard 67170460 bcd
[root@localhost test]# rm bcd 
rm: remove regular file ?.cd?. y
[root@localhost test]# cat abc.hard 
qwer 
dfd
[root@localhost test]# ll -i
total 4
67170460-rw-r--r--.1 root root 10Jul1220:39 abc.hard

 四 软链接特征

1、把原文件删除,软链接文件无法使用。

2、虽然软链接文件的权限是777,但真正的权限还是由原文件决定。

3、创建软链接时,如果原文件和目标文件在一个目录下,不用写绝对路径,否则原文件和目标文件必须写绝对路径。所以原文件一定要写绝对路径。

五 实战

[root@localhost test]# ls
abc
[root@localhost test]# ln -s abc abc.soft
[root@localhost test]# ll
total 0
-rw-r--r--.1 root root 0Jul1220:42 abc
lrwxrwxrwx.1 root root 3Jul1220:55 abc.soft -> abc
[root@localhost test]#in abc abc.hard
-bash: syntax error near unexpected token `in'
[root@localhost test]# ln abc abc.hard
[root@localhost test]# ll
total 0
-rw-r--r--. 2 root root 0 Jul 12 20:42 abc
-rw-r--r--. 2 root root 0 Jul 12 20:42 abc.hard
lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc
[root@localhost test]# ls -i
67170460 abc 67170460 abc.hard 67170462 abc.soft
[root@localhost test]# echo 111 >>abc
[root@localhost test]# cat abc.soft 
111
[root@localhost test]# cat abc.hard 
111
[root@localhost test]# echo 222 >> abc.soft 
[root@localhost test]# cat abc
111
222
[root@localhost test]# cat abc.soft 
111
222
[root@localhost test]# rm -rf abc
[root@localhost test]# ll
total 4
-rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc
[root@localhost test]# cat abc.hard 
111
222
[root@localhost test]# rm -rf abc.soft 
[root@localhost test]# ll
total 4
-rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
[root@localhost test]# touch abc
[root@localhost test]# ln -s abc.soft
[root@localhost test]# ls
abc abc.hard abc.soft
[root@localhost test]# ll -i
total 4
67170462 -rw-r--r--. 1 root root 0 Jul 12 21:01 abc
67170460 -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard
67170463 lrwxrwxrwx. 1 root root 8 Jul 12 21:01 abc.soft -> abc.soft
[root@localhost test]# rm -rf *
[root@localhost test]# ll
total 0
[root@localhost test]# touch abc
[root@localhost test]# ln -s abc abc.soft
[root@localhost test]# ll
total 0
-rw-r--r--. 1 root root 0 Jul 12 21:05 abc
lrwxrwxrwx. 1 root root 3 Jul 12 21:05 abc.soft -> abc
[root@localhost test]# ln -s abc /tmp/ab.soft
[root@localhost test]# ll /tmp
total 0
lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc
drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
[root@localhost test]# ll /tmp
total 0
lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc
drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
[root@localhost test]# rm -rf /tmp/ab.soft
[root@localhost test]# ln -s /root/test/abc /tmp/ab.soft
[root@localhost test]# ll /tmp
total 0
lrwxrwxrwx. 1 root root 14 Jul 12 21:08 ab.soft -> /root/test/abc
drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan

六 硬链接和软链接文件访问示意图

以上就是Linux链接命令的详解,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

  • Shell脚本实现自动检测修改最快的Ubuntu软件源

    Shell脚本实现自动检测修改最快的Ubuntu软件源

    这篇文章主要介绍了Shell脚本实现自动检测修改最快的Ubuntu软件源,本文先是讲解了实现的思路,并给了实现脚本源码,需要的朋友可以参考下
    2014-10-10
  • Linux进程间通信——使用流套接字

    Linux进程间通信——使用流套接字

    本篇文章将会简单地讲述如何使用socket进行简单的网络编程。具有很好的参考价值。下面跟着小编一起来看下吧
    2017-04-04
  • Shell 管道及执行顺序分析

    Shell 管道及执行顺序分析

    Shell 管道及执行顺序分析,需要的朋友可以参考下
    2013-01-01
  • 一天一个shell命令 linux文本操作系列-head,tail命令详解

    一天一个shell命令 linux文本操作系列-head,tail命令详解

    这篇文章主要介绍了一天一个shell命令 linux文本操作系列-head,tail命令详解,需要的朋友可以参考下
    2016-06-06
  • Shell 函数参数

    Shell 函数参数

    这篇文章主要为大家分享了Shell 函数参数,方便学习shell脚本的朋友
    2014-09-09
  • shell模糊匹配与正则详解

    shell模糊匹配与正则详解

    这篇文章主要介绍了shell模糊匹配与正则详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-10-10
  • shell脚本去重的三种方法小结

    shell脚本去重的三种方法小结

    在实际工作中,进行Shell去重操作是非常常见的任务之一,本文主要介绍了shell脚本去重的三种方法小结,具有一定的参考价值,感兴趣的可以了解一下
    2023-12-12
  • 使用shell脚本一键部署LNMP架构的方法

    使用shell脚本一键部署LNMP架构的方法

    这篇文章主要介绍了使用shell脚本一键部署LNMP架构的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-01-01
  • 结合示例说明shell是如何被解析的

    结合示例说明shell是如何被解析的

    本文主要介绍了结合示例说明shell是如何被解析的,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-12-12
  • Shell $0, $#, $*, $@, $?, $$和命令行参数的使用

    Shell $0, $#, $*, $@, $?, $$和命令行参数的使用

    这篇文章主要介绍了Shell $0, $#, $*, $@, $?, $$和命令行参数的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-05-05

最新评论