Announcement

Collapse
No announcement yet.

<SOLVED> symlink creation issues - simple problem?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    <SOLVED> symlink creation issues - simple problem?

    I've never been at ease with the "ln" CLI command. It seems all but inscrutable in its complexities, and foils me every time I try to use it. I'm trying again tonight.

    I come from Windows, where creating a link to another file in the very easy, and in fact available from the right-click menu. Very user-friendly. Nothing like this exists in Linus, so far as I can tell. I very much wish it did.

    Meanwhile, I still need this functionality. I've dug through all the documentation I can find - the info page output, and the output from info coreutils 'ln invocation', and I still cannot get it right. I've studied a couple of tutorials on relative and absolute pathnames, and found them not useful to me, in that they didn't lead me to a working symlink creation command. I'm baffled as to why this simple operation is so elusive to me. Here's what I'm trying to do:

    I have a file here: "/home/tomc/E-books/filex.pdf"

    I want a link to it that will survive being moved to another location.

    I've tried all these, and none actually work:

    ln -s "filex.pdf" "link to filex.pdf"
    ln -s "../filex.pdf" "link to filex.pdf"
    ln -s "../../filex.pdf" "link to filex.pdf"
    ln -s "../../../filex.pdf" "link to filex.pdf"

    One of these should have worked, according to my understanding of the coreutils documentation, but alas...

    I would greatly appreciate a working example of how to do this.


    #2
    Re: symlink creation issues - simple problem?

    I just did a little experiment to do what you did, here are my results:

    Code:
    #Show working directory:
    :~/test$ pwd
    /home/ATL/test
    #Create two directories: "test1" and "test2"
    :~/test$ mkdir test1 test2
    
    #Verify that they were created
    :~/test$ ls        
    test1 test2
    
    #Create blank file "test.txt"
    :~/test$ touch test.txt
    
    #Add the text "test123" to the "test.txt" file:
    :~/test$ echo "test123" > test.txt
    
    #Verify that "test123" exists in that file:
    :~/test$ cat test.txt
    test123
    
    #Open the "test1" directory"
    :~/test$ cd test1/
    
    #Create a symlink to the test.txt file in previous directory:
    :~/test/test1$ ln -s /home/ATL/test/test.txt
    
    #Navigate to previous directory
    :~/test/test1$ cd ..
    
    #List contents, test.txt file is still there
    :~/test$ ls
    test1 test2 test.txt
    
    #Display contents of test1/test.txt file (the symlink)
    :~/test$ cat test1/test.txt
    test123
    #This matches.
    
    #Move the test.txt symlink from the "test1" directory to the "test2" directory:
    :~/test$ mv test1/test.txt test2/
    
    #Show contents of the test.txt symlink in the "test2" directory
    :~/test$ cat test2/test.txt
    test123
    #This matches.
    
    #Show that this file is indeed a symlink, not a copied file:
    :~/test/test2$ ls -l
    total 0
    lrwxrwxrwx 1 ATL ATL 25 2009-06-21 23:00 test.txt -> /home/ATL/test/test.txt
    :~/test/test2$
    Success...
    eMachines E520 notebook, 2ghz celeron, 3gb RAM, 160gb HDD, etc... woot.com special with no Microsoft tax running Kubuntu 9.04 beautifully

    Comment


      #3
      Re: symlink creation issues - simple problem?

      Very interesting, and helpful. I learned several things from your example. THANKS!

      Now I'm off to give it a try.

      t.

      Comment


        #4
        Re: symlink creation issues - simple problem?

        I have some puzzling results. In summary:

        Your example works fine for me, using a text file. I get exactly the results you got: the link does exactly what it should, which opened.

        However, my target files are PDF files, and these do NOT work. Using your precise method -

        ln -s "{pathname}xxx.pdf" leads to the result I've been getting all night, with all methods I've tried - yours or mine: My PDF reader (and it doesn't matter which of the 3 installed I use) opens and displays this message:

        "There was an error opening this document. This file cannot be found."

        I have no idea why this is happening. Any ideas?

        Comment


          #5
          Re: symlink creation issues - simple problem?

          pdf seems to work for me, here are my results but using relative path instead of absolute path:

          Code:
          :~/test$ pwd
          /home/ATL/test   
          :~/test$ ls 
          kmymoney-user.pdf test1 test2
          :~/test$ md5sum kmymoney-user.pdf 
          b4fd23e0a1a380ee669a954aee1e3c53 kmymoney-user.pdf
          :~/test$ cd test1/            
          :~/test/test1$ ln -s ../kmymoney-user.pdf 
          :~/test/test1$ ls
          kmymoney-user.pdf
          :~/test/test1$ md5sum kmymoney-user.pdf
          b4fd23e0a1a380ee669a954aee1e3c53 kmymoney-user.pdf
          :~/test/test1$ cd ..
          :~/test$ ls
          kmymoney-user.pdf test1 test2
          :~/test$ mv test1/kmymoney-user.pdf test2/
          :~/test$ ls test1/
          :~/test$ ls test2/
          kmymoney-user.pdf
          :~/test$ md5sum test2/kmymoney-user.pdf
          b4fd23e0a1a380ee669a954aee1e3c53 test2/kmymoney-user.pdf
          :~/test$ cd test2/
          :~/test/test2$ ls -l
          total 0
          lrwxrwxrwx 1 ATL ATL 20 2009-06-22 09:47 kmymoney-user.pdf -> ../kmymoney-user.pdf
          :~/test/test2$
          I can then open dolphin and open the kmymoney-user.pdf file using the symlink in the test2 directory and it works fine

          It sounds like a path problem for your symlink, can you post more details about your paths and your ls -l info?
          eMachines E520 notebook, 2ghz celeron, 3gb RAM, 160gb HDD, etc... woot.com special with no Microsoft tax running Kubuntu 9.04 beautifully

          Comment


            #6
            Re: symlink creation issues - simple problem?

            Originally posted by tomcloyd
            I come from Windows, where creating a link to another file in the very easy, and in fact available from the right-click menu. Very user-friendly. Nothing like this exists in Linus, so far as I can tell. I very much wish it did.
            Ahhhhhh....but it does! If I understand what you are trying to do...if you open dolphin, and drag the file to another location (you can even do this across tabs), when you release the mouse button, a dialog box will ask you if you want to move, copy, etc...one of those options will be to link. I believe (although not 100% sure) that if you choose link, it just creates a symlink wherever you dropped the file.
            Dell Inspiron 1720 Laptop<br />Intel T9300 Core2Duo Processor @ 2.5Ghz<br />4 GB Ram | 1920 X 1200 Resolution<br />2 X 160 GB SATA HD Internal<br />Nvidia GeForce 8600M Graphics Adapter<br />Using Kubuntu 9.10

            Comment


              #7
              Re: symlink creation issues - simple problem?

              Originally posted by muzicman0
              Originally posted by tomcloyd
              I come from Windows, where creating a link to another file in the very easy, and in fact available from the right-click menu. Very user-friendly. Nothing like this exists in Linus, so far as I can tell. I very much wish it did.
              Ahhhhhh....but it does! If I understand what you are trying to do...if you open dolphin, and drag the file to another location (you can even do this across tabs), when you release the mouse button, a dialog box will ask you if you want to move, copy, etc...one of those options will be to link. I believe (although not 100% sure) that if you choose link, it just creates a symlink wherever you dropped the file.
              Well. Hmmm. I've been wondering for a while if it's time for new glasses for my aging eyes. We just may have answered that question! I had NEVER noticed that "link" option. Incredible. What it creates is a HARD LINK.

              From the output of
              Code:
              info coreutils ‘ln invocation’
              -

              A "hard link" is another name for an existing file; the link and the
              original are indistinguishable. Technically speaking, they share the
              same inode, and the inode contains all the information about a
              file--indeed, it is not incorrect to say that the inode _is_ the file.


              But, a hard link, if I understand correctly, is NOT a file copy. Just a pointer, as it were. Exactly what I'm after.

              Ah, it's a good day for this Linux lover.

              My thanks to you.

              Comment

              Working...
              X