ln -s /dir1/file1 /dir2/file1
我想在目标 dir1 中创建一个软链接,文件名与 dir2 中的源文件名相同
如果您要创建多个符号链接,一遍又一遍地输入名称会非常令人沮丧。这是我绕过在 Linux 中重新输入名称的方法。
这是我的示例文件结构:
source/
- file1.txt
- file2.js
- file3.js
target/
~$ ln -sr source/file2.js target/
结果:
source/
- file1.txt
- file2.js
- file3.js
target/
- file2.js
source
~$ ln -sr source/*.js target/
结果:
source/
- file1.txt
- file2.js
- file3.js
target/
- file2.js
- file3.js
source
~$ ln -sr source/* target/
结果:
source/
- file1.txt
- file2.js
- file3.js
target/
- file1.txt
- file2.js
- file3.js
注意r
选项。如果不包括-r
链接源,则必须相对于链接位置输入。
~$ ln -s ../source/file1.txt target/
作品~/target$ ln -s ../source/file1.txt .
作品~$ ln -s source/file1.txt target/
不工作也可以看看:
您可以使用ln
-only 选项来执行此操作:
ln -s -t /dir1 /dir2/file1