前言

  • 文章来源:CSDN@LawsonAbs

1.软连接

1.1 创建语法

ln -s target source
解释下:
ln -s:表示创建一个软连接;
target:表示目标文件(夹)【即被指向的文件(夹)】
source:表示当前目录的软连接名。

1.2 具体示例

  • step 1.创建测试文件及文件夹
[root@server6 ~]# mkdir test_chk
[root@server6 ~]# touch test_chk/test.txt
[root@server6 ~]# echo "hello spark" > test_chk/test.txt
[root@server6 ~]# cat test_chk/test.txt
hello spark
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:41 test_chk
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# ln -s test_chk/ test_chk_ln
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:41 test_chk
lrwxrwxrwx.  1 root root     9 11月  4 10:42 test_chk_ln -> test_chk/
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk_ln/
[root@server6 test_chk_ln]# ll
总用量 4
-rw-r--r--. 1 root root 12 11月  4 10:41 test.txt
[root@server6 test_chk_ln]# cat test.txt
hello spark
[root@server6 test_chk_ln]# ll
总用量 4
-rw-r--r--. 1 root root 12 11月  4 10:41 test.txt
[root@server6 test_chk_ln]# cat test.txt
hello spark

2.注意

2.1 创建软连接时,不用创建文件夹。

2.2 命令示例解释

执行的命令是: ln -s /storage/lawson/scores scor
其含义就是:将scor指向 /storage/lawson/scores/目录下

这里是当前的scor 指向 /storage/lawson/scores 中。这里显示红色,是因为/storage/lawson/scores这个目录不存在,如果创建该目录,那就可以得到蓝色的显示了。

需要注意的是,当前所有目录下的文件都不能重名,因为我之前有一个文件夹是scores,所以这里就简单的命名成了scor

2.3 软连接的删除

rm -rf ./test_chk_ln/ 会删除文件夹下的所有内容,但是没有删除这个链接;
rm -rf ./test_chk_ln 则是仅删除这个软链接,不会删除下面的内容。

  • 错误示范
[root@server6 test_chk_ln]# cd ..
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:41 test_chk
lrwxrwxrwx.  1 root root     9 11月  4 10:42 test_chk_ln -> test_chk/
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# rm -rf ./test_chk_ln/
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root     6 11月  4 10:42 test_chk
lrwxrwxrwx.  1 root root     9 11月  4 10:42 test_chk_ln -> test_chk/
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk
[root@server6 test_chk]# ll
总用量 0
[root@server6 test_chk]# ll
总用量 0

可以发现该文件夹下的内容都被删了。。。

  • 正确删除软连接
[root@server6 ~]# rm -rf ./test_chk_ln
[root@server6 ~]# ll
总用量 84
-rw-------.  1 root root  1257 6月  16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root  4096 11月  1 10:28 azkabanJob
-rw-r--r--.  1 root root 67322 11月  4 10:24 azkabanJob.zip
drwxr-xr-x.  4 root root    37 7月  13 11:01 hadoop_temp
-rw-r--r--.  1 root root    54 7月   4 14:11 HelloLinux.txt
drwxr-xr-x.  2 root root    22 11月  4 10:44 test_chk
-rw-r--r--.  1 root root    67 10月  8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk/
[root@server6 test_chk]# ll
总用量 4
-rw-r--r--. 1 root root 12 11月  4 10:44 test.txt

参考文章

  • https://www.cnblogs.com/cartsp/p/6437046.html

Linux 命令之软连接详解相关推荐

  1. 【转】Linux命令工具 top详解

    Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来不 ...

  2. linux中top工具,Linux命令工具 top详解

    Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来不 ...

  3. linux su命令位置,Linux命令大全su详解

    su允许某用户暂时成为另一个用户.它以真实有效的user ID.group ID和给定USER的附加组,执行一个命令,通常是一个交互式的shell.接下来是小编为大家收集的Linux命令大全su详解, ...

  4. Linux命令工具 top详解

    Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似 于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来 ...

  5. 离线调用linux命令,GitHub - rinetd/linux-command: Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。...

    Linux Command 516 个 Linux 命令大全,内容包含 Linux 命令手册.详解.学习,值得收藏的 Linux 命令速查手册.请原谅我写了个爬虫,爬了他们家的数据linuxde.ne ...

  6. 实验楼linux命令,GitHub - encorechow/linux-command: Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。...

    Linux Command 516 个 Linux 命令大全,内容包含 Linux 命令手册.详解.学习,值得收藏的 Linux 命令速查手册.请原谅我写了个爬虫,爬了他们家的数据linuxde.ne ...

  7. spark常用的linux命令,GitHub - Sparkinzy/linux-command: Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。...

    Linux Command 516 个 Linux 命令大全,内容包含 Linux 命令手册.详解.学习,值得收藏的 Linux 命令速查手册.请原谅我写了个爬虫,爬了他们家的数据linuxde.ne ...

  8. linux命令之-dmesg详解

    Linux命令dmesg用法详解 功能说明:显示开机信息.  语 法:dmesg [-cn][-s <缓冲区大小>]  补充说明:kernel会将开机信息存储在ring buffer中.您 ...

  9. Linux命令--tree--使用/详解/实例

    原文网址: 见:Linux命令--tree--使用/详解/实例_IT利刃出鞘的博客-CSDN博客 简介 本文用示例介绍Linux的tree命令的用法. tree命令可以以树状结构查看目录结构. 选项 ...

最新文章

  1. java基础学完就直接学ssm_java基础学习笔记3(SSM基础)
  2. 验证dropdownlist必选
  3. NET Core微服务之路:SkyWalking+SkyApm-dotnet分布式链路追踪系统的分享
  4. 5W-Lora电台的远距离传输优势
  5. java 删除图形界面_Java图形化界面报错?
  6. word2vec 细节解析1
  7. 数字信号处理--7.5--FIR数字滤波器
  8. legend---六、php脚本变量的生命周期是怎样的
  9. 分析华为毕昇JDK8:类数据共享CDS有效果,幅度很小
  10. 编译安装Nginx以及配置运行Drupal 8,实现上传进度功能
  11. python飞机大战项目概述需求_飞机大战需求分析报告.doc
  12. com.itextpdf.text.exceptions.IllegalPdfSyntaxException: Unbalanced save/restore state operators
  13. Wallpaper (18)
  14. 数学建模 —— 规划模型
  15. 自定义函数fac1用递推方法求n!,自定义函数fac2用递归方法求n!,主函数中输入整数n(0≦n≦10)后,分别调用函数fac1和函数fac2求n!,最后输出调用的结果值进行对比。
  16. word排版案例报告_导师:论文排版都搞不好,你拿什么去投稿?!
  17. 针对安卓app的爬虫路程
  18. 如何向一个普通人说明什么是物联网?
  19. Html5 canvas创意特效合集
  20. r语言随机森林_随机森林+时间序列(R语言版)

热门文章

  1. SR660 V2 英特尔 X710 和博通网卡温度在 Web 上显示为 0
  2. Disruptor简介及使用示例
  3. 呼入型呼叫中心系统的ACD排队规则
  4. centos yum安装提示Some packages in your transaction are brought to you by GetPageSpeed
  5. java阻塞队列和非阻塞队列的区别
  6. webpack搭建vue项目(不用脚手架)
  7. spring-boot学习
  8. CNNFeatures Off-the-Shelf: An Astounding Baseline for Recognition
  9. Hive窗口函数练习题(连续三天以上有销售记录的店铺)
  10. 通读《技术管理实战36讲》1、自我倾听篇