I tried to create a symbolic link of Books Directory to the Home
#in the Document Directory to the Home Diretory.
ln -s Books/ ~/Books
but it create a file rather than a directory
What's the problem with my usage of ln?
This looks like 3rd form according to documentation:
ln [OPTION]... TARGET... DIRECTORY (3rd form) ... In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
So it reads as "create link to a directory Books
(which is in your current working directory) and put that link in specified directory ~/Books
". Of course, if Books/
doesn't exist in current working directory - you'll have a symlink pointing to itself, which will result in too many symlink levels error
[ adminx:Fri Feb 22 01:57:21 UTC 2019 ]$ ln -s asdfasdf foobarbaz/
[ adminx:Fri Feb 22 01:57:33 UTC 2019 ]$ ls foobarbaz/
asdfasdf file.txt thing
[ adminx:Fri Feb 22 01:57:37 UTC 2019 ]$ ls -l foobarbaz/
total 0
lrwxrwxrwx 1 adminx adminx 8 Feb 22 01:57 asdfasdf -> asdfasdf
-rw-rw-r-- 1 adminx adminx 0 Feb 22 01:56 file.txt
lrwxrwxrwx 1 adminx adminx 5 Feb 22 01:56 thing -> thing
[ adminx:Fri Feb 22 02:02:29 UTC 2019 ]$ cd foobarbaz/thing
bash: cd: foobarbaz/thing: Too many levels of symbolic links
Now, I would suggest using first form with -T
flag:
adminx:Fri Feb 22 02:05:01 UTC 2019 ]$ ln -s -T ~/Documents dock_link
[ adminx:Fri Feb 22 02:05:08 UTC 2019 ]$ ls -l dock_link
lrwxrwxrwx 1 adminx adminx 22 Feb 22 02:05 dock_link -> /home/adminx/Documents
[ adminx:Fri Feb 22 02:05:16 UTC 2019 ]$
It seems like you created a broken link. Books/
is in ~/Documents
, so you need to specify that, either with a relative path:
ln -s Documents/Books ~/Books
or an absolute path:
ln -s ~/Documents/Books ~/Books
ln -s /home/username/Documents/Books /home/username/Books