How to create a link to an existing file or directory using a GNU Linux shell command?
-
@jcollum: Probably so... UnixSE has this similar Q&A for example, but the selected answer here seems a better one.– user5395338Jul 18, 2020 at 8:29
-
ln -s /data/data/com.termux/files/usr/lib/python3.9/site-packages /data/data/com.termux/files/usr/lib/python3.10/site-packages– CS QGBNov 2, 2021 at 10:59
2 Answers
Symbolic or soft link (files or directories, more flexible and self documenting)
# Source Link
ln -s /home/jake/doc/test/2000/something /home/jake/xxx
Hard link (files only, less flexible and not self documenting)
# Source Link
ln /home/jake/doc/test/2000/something /home/jake/xxx
More information: man ln
/home/jake/xxx
is like a new directory. To avoid "is not a directory: No such file or directory" error, as @trlkly comment, use relative path in the target, that is, using the example:
cd /home/jake/
ln -s /home/jake/doc/test/2000/something xxx
-
61Do note that you have to use a full path for this syntax. I wound up having to use
ln "$(pwd)/relative_path" xxx
in order to get an absolute link forxxx
using a relative path. Apparently, bash clobbering rules are not expanded for the SOURCE.– trlklyJan 6, 2016 at 3:24 -
-
1
-
-
1As trlkly said, write the full path manually. The "ln" command does not expand even the home directory "~". Nov 10, 2019 at 15:31
you should use :
ln -s /home/jake/doc/test/2000/something xxx