0. 总结
# create soft link, file
ln -s origin.txt shortcut.txt
# create soft link, dictionary
ln -s origin/ shortcut/
# remove soft link
rm shortcut/
# or
unlink shortcut
# rewrite soft link
ln -sf new_origin shortcut
1. ln
能做什么
ln
能创建符号链接(symlink),比如为某个文件或文件夹创建快捷方式
2. Linux 中软连接和硬连接区别
软连接可以【指向】源文件
硬连接会创建一份源文件的【拷贝】
3. 怎么使用 ln
3.1 创建软连接
基本语法如下:
ln -s origin.txt shortcut.txt
-s: 表示创建软连接
origin:源文件或文件夹
shortcut:快捷方式的名字
查看是否成功建立软连接:
ls -l
######
shortcut.txt -> origin.txt
3.2 删除软连接
方法一:删除快捷方式:rm shortcut.txt
方法二:使用专门命令:unlink shortcut.txt
3.3 覆盖之前的软连接
假设我们有个 shortcut.txt -> origin.txt 的连接,我们希望让 shortcut.txt 指向新的文件 origin2.txt.
那么我们可以使用 -f
关键字
ln -sf origin2.txt shortcut.txt
4. 参考
https://www.freecodecamp.org/news/linux-ln-how-to-create-a-symbolic-link-in-linux-example-bash-command/
欢迎各位来关注我的个人网站:https://tyyuan110.com/
我会在上面定期更新相关技术博客(前端、测开、面经等),谢谢!