linux学习100篇59:创建软连接

为啥要用软连接?
跟cp有啥差別?cp不香吗?
优点:
1.相当于 Windows下的快捷方式,方便操作
2.节约空间

ln:Link链接,分软链接(常用)和硬接(默认)
常见参数:不加参数即为硬链接,加上-s参数即为软链接,
软链接的作用类似快捷方式
常见用法:ln -s TARGET DIRECTORY

root 02:59:03 ~
$ mkdir ln  
root 02:59:33 ~
$ ls -lh
total 54M
-rw-r--r--  1 root root    0 May 27 13:16 a.txt
drwxr-xr-x  6 root root 4.0K May 27 13:16 data
drwxr-xr-x  2 root root 4.0K May 28 02:59 ln
drwxr-xr-x 17 root root 4.0K May 26 14:03 miniconda3
-rw-r--r--  1 root root  54M Mar  2 17:39 rstudio-server-1.4.1106-amd64.deb
drwxr-xr-x  2 root root 4.0K May 26 13:34 software
drwxr-xr-x  2 root root 4.0K May 26 11:52 temp
drwxr-xr-x  3 root root 4.0K May 28 02:49 test_file1
-rw-r--r--  1 root root    0 May 28 02:34 test_file3
root 02:59:37 ~
$ ln -s a.txt ln
root 02:59:55 ~
$ cd ln
root 03:00:07 ~/ln
$ ls 
a.txt
root 03:00:10 ~/ln
$ ln -s /root/miniconda3/ ./
root 03:01:53 ~/ln
$ ls -lh
total 0
lrwxrwxrwx 1 root root  5 May 28 02:59 a.txt -> a.txt
lrwxrwxrwx 1 root root 17 May 28 03:01 miniconda3 -> /root/miniconda3/
root 03:01:58 ~/ln
$ ls -s /root/a.txt ./
0 /root/a.txt

./:
total 0
0 a.txt  0 miniconda3
root 03:03:17 ~/ln
$ ls -lh
total 0
lrwxrwxrwx 1 root root  5 May 28 02:59 a.txt -> a.txt
lrwxrwxrwx 1 root root 17 May 28 03:01 miniconda3 -> /root/miniconda3/
root 03:03:29 ~/ln
$ 

你可能感兴趣的:(linux学习100篇59:创建软连接)