[SOLVED] Why can't I access any symbolic links that I create to what they're pointing?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why can't I access any symbolic links that I create to what they're pointing?
Hi, this is a bit noob, but everytime I try to create softlinks to some files/dirs, I can't access them, I either get "Too many symlinks" (or something) or "No such file/dir". I'm pretty sure that I typed the addresses correctly.
I just have some songs, in my ext4 data drive, that I want to link to my ~/music dir.
Note that when I create the links in that dir, and go to that dir with midnight commander, they're colored in red. (broken?)
Hmmm, but the way I was linking them, was actually in the mc command line, like this:
1- I highlight the things I wanna link.
2- I do: 'ln -s <dump the files with Ctrl+x, t> ~/music/'
So...?
---------- Post added 03-11-13 at 12:38 PM ----------
Hmm... I think I shouldn't just, dump the files, cuz that way, their full path isn't specified, I think it should be their full path that I must type.
Yes... that was it. But why? I mean, in mc, you know there are 2 panels, in the right panel, I was sitting in my songs dir, which is
'/mnt/d/SNG' and on the left, I was in '~/temp'. From the right panel, I did the linking (the way I wrote above), and in temp, I see that they are red...
The link will be created in the destination using the exact name and path you specify. This means that the path you specify to the source must be the path when viewed from the destination. Relative paths are fine, but they must be relative from the destination dir, not from where your pwd is. See this thread for more info:
HAHA! I just fixed my problem, wrote a script for that linking, hope somebody will find it useful:
Code:
1 #!/bin/bash
2
3 # What's this?
4 # This will let you link, more than one file/dir from your current working dir to dest, without having to specify the whole path
5 # which is relative to the destination.
6 # Example:
7 # /mnt/drive/music $> ls
8 # /mnt/drive/music $> song1 song2 song3 some album.1 some album.2
9 # /mnt/drive/music $> slink ~/music song* some\ album.1 some\ album.2
10 # This will link all the 3 songs and the other 2 files, to ~/music, that was fast, huh?
11
12 # $# is the number of args passed to the script.
13 let args=$#;
14 usage="Usage: slink <destination> file(s)/directory(ies)\nThe file(s)/dir(s) in the 2rd arg, should be in your current working directory.
15 if the 2nd arg isn't specified, current working directory will be linked to destination."
16 if [ "$args" -lt 1 ]
17 then
18 echo -e $usage; #using -e will let echo process the escaping character, otherwise, it'll just print them.
19 exit 1;
20 fi;
21
22 source=`pwd`;
23 dest=$1;
24 if [ "$args" == 1 ]
25 then
26 ln -s $source $dest;
27 else
28 for file in "$@"
29 do
30 if [ "$file" == "$dest" ];then
31 continue;
32 fi;
33 ln -s $source/"$file" $dest; # DON'T YOU FORGET ABOUT THE QUOTES!!! Otherwise, spaces will be ignored.
34 done;
35 fi;
The script can probably do with some work, but not a bad first draft. i did find the following curious:
Quote:
# DON'T YOU FORGET ABOUT THE QUOTES!!! Otherwise, spaces will be ignored.
Is there a reason why the quotes on the line mentioned are only around 1 of the 3 variables listed and for that matter, why they are not employed for all variables in your script?
In re the above; given that that warning applies to just about every *nix cmd, you're much better off renaming files with no spaces eg use underscores instead.
@grail: Mmm, mostly because, if anything will have spaces, it will be $file. Most of my directories doesn't have spaces.
So yes, to make it bullet-proof, surround $source and $dest with quotes as well, it's better, it won't hurt.
Thanks for pointing it out :-)
@chrism01: I agree, underscores saves you a lot of headaches, maybe I'll make some script, that replaces the spaces, you have in your files in some dir...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.