You can do it with ln
-only options:
ln -s -t /dir1 /dir2/file1
質問
ln -s /dir1/file1 /dir2/file1
I'd like to create a softlink in target dir1 with same filename as source in dir2 How is this done without typing the file1 name over in the target path
解決 2
You can do it with ln
-only options:
ln -s -t /dir1 /dir2/file1
他のヒント
It is very frustrating typing the name over and over again if you're creating several symlinks. Here's how I bypass retyping the name in Linux.
Here's my example file structure:
source/
- file1.txt
- file2.js
- file3.js
target/
~$ ln -sr source/file2.js target/
Result:
source/
- file1.txt
- file2.js
- file3.js
target/
- file2.js
source
~$ ln -sr source/*.js target/
Result:
source/
- file1.txt
- file2.js
- file3.js
target/
- file2.js
- file3.js
source
~$ ln -sr source/* target/
Result:
source/
- file1.txt
- file2.js
- file3.js
target/
- file1.txt
- file2.js
- file3.js
Notice the r
option. If you don't include -r
the link source must be entered relative to the link location.
~$ ln -s ../source/file1.txt target/
Works~/target$ ln -s ../source/file1.txt .
Works~$ ln -s source/file1.txt target/
Does not workSee also:
How to create symbolic links to all files (class of files) in a directory?