LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-11-2013, 12:22 PM   #1
Vexe
Member
 
Registered: Feb 2013
Posts: 36

Rep: Reputation: Disabled
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!
 
Old 03-11-2013, 12:26 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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.
 
Old 03-11-2013, 12:37 PM   #3
Vexe
Member
 
Registered: Feb 2013
Posts: 36

Original Poster
Rep: Reputation: Disabled
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.
 
Old 03-11-2013, 12:40 PM   #4
Vexe
Member
 
Registered: Feb 2013
Posts: 36

Original Poster
Rep: Reputation: Disabled
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...
 
Old 03-11-2013, 12:40 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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/

Last edited by suicidaleggroll; 03-11-2013 at 12:42 PM.
 
1 members found this post helpful.
Old 03-11-2013, 12:47 PM   #6
Vexe
Member
 
Registered: Feb 2013
Posts: 36

Original Poster
Rep: Reputation: Disabled
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?

Last edited by Vexe; 03-11-2013 at 12:56 PM.
 
Old 03-13-2013, 02:50 PM   #7
Vexe
Member
 
Registered: Feb 2013
Posts: 36

Original Poster
Rep: Reputation: Disabled
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;

Last edited by Vexe; 03-13-2013 at 02:58 PM.
 
Old 03-13-2013, 06:59 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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?
 
Old 03-13-2013, 11:13 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 03-13-2013, 11:19 PM   #10
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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>

Last edited by shivaa; 03-13-2013 at 11:20 PM.
 
Old 03-14-2013, 01:56 PM   #11
Vexe
Member
 
Registered: Feb 2013
Posts: 36

Original Poster
Rep: Reputation: Disabled
@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...
 
Old 03-15-2013, 01:58 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
1 members found this post helpful.
  


Reply

Tags
softlink, symbolic link



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
create symbolic links from recurisve folders? xmrkite Linux - Software 13 06-08-2010 12:11 PM
can I create symbolic links for multiple files simutaneously cliffyao Linux - Newbie 3 02-18-2010 03:11 PM
how to create jar files with symbolic links alps963 Linux - General 1 05-03-2008 06:30 AM
How to find all symbolic links pointing to a particular file? Akhran Linux - Newbie 5 11-19-2005 06:25 AM
How to search for files that are symbolic links pointing to a particular file? Akhran Linux - Newbie 1 10-13-2005 07:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration