LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why can't I access any symbolic links that I create to what they're pointing? (https://www.linuxquestions.org/questions/linux-newbie-8/why-cant-i-access-any-symbolic-links-that-i-create-to-what-theyre-pointing-4175453641/)

Vexe 03-11-2013 12:22 PM

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?)

I'm using 'ln -s /path/to/file(s) /path/to/dir'

What am I missing here?

Thanks!

suicidaleggroll 03-11-2013 12:26 PM

Perhaps an example would help. Post an "ls -l" for the files and the dir before and after making the links.

From the sound of it everything should be fine, so there must be a problem with the way you're writing the actual command.

Vexe 03-11-2013 12:37 PM

Heh, that's strage it worked when I did:
Code:

vexe ~/temp $ ln -s /mnt/d/SNG/Intro.mp3 intro.mp3
vexe ~/temp $ ls
intro.mp3
vexe ~/temp $ mplayer intro.mp3

mplayer played the song successfully.

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.

Vexe 03-11-2013 12:40 PM

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...

suicidaleggroll 03-11-2013 12:40 PM

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:

http://www.linuxquestions.org/questi...ks-4175450384/

Vexe 03-11-2013 12:47 PM

I guess that's easily solved with MC's Ctrl+Shitf+Enter which gives you the full path to the selected item.

Thanks :)

EDIT: Ctrl+Shift+Enter works on the current selected item, not the whole selection of items :(

Does anyone know how to?

Vexe 03-13-2013 02:50 PM

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;


grail 03-13-2013 06:59 PM

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?

chrism01 03-13-2013 11:13 PM

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.

shivaa 03-13-2013 11:19 PM

The words destination or dest are always confusing while using it in terms of symlink creation. Instead, the simple syntax is:

Code:

~$ ln -s /path/to/file /path/to/<linkname>

Vexe 03-14-2013 01:56 PM

@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...

chrism01 03-15-2013 01:58 AM

Here's a simple script to cvt spaces to underscores (assuming ls >t.t)
Code:

IFS=$'\n'

for file in $(cat t.t)
do
    new_file=$(echo $file |sed -e 's/ /_/g')
    echo $new_file
#    mv "$file" $new_file
done

Uncomment the mv cmd when you are happy with it.


All times are GMT -5. The time now is 10:32 AM.