ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Symbolically Linking Files

    Scheduled Pinned Locked Moved IT Discussion
    linuxsam linux administrationsymlink
    14 Posts 4 Posters 3.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • iroalI
      iroal @scottalanmiller
      last edited by

      @scottalanmiller

      First, Thanks a lot for these tutorials are really useful for me.

      I get the error "No such file or directory" when execute "cd my dir" in:

      cd /tmp
      ln -s mydir /var/log
      cd mydir

      If I go to /var/log I can see the Link file created before.

      scottalanmillerS 1 Reply Last reply Reply Quote 0
      • scottalanmillerS
        scottalanmiller
        last edited by

        Should be "cd mydir" without the space. You can do an ls to see what you have stored there.

        1 Reply Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller @iroal
          last edited by

          @iroal said:

          If I go to /var/log I can see the Link file created before.

          Hmmm... nothing should have been created in there. Which file appeared in there?

          1 Reply Last reply Reply Quote 0
          • iroalI
            iroal
            last edited by

            0_1455093508778_Clipboard02.jpg

            It's Centos 7, spanish. let my know if you need any test.

            1 Reply Last reply Reply Quote 0
            • scottalanmillerS
              scottalanmiller
              last edited by

              Ah yes, you have discovered a typo in my copying over from one system to the other. The linking command should have been...

              # ln -s /var/log mydir
              
              iroalI 1 Reply Last reply Reply Quote 1
              • iroalI
                iroal @scottalanmiller
                last edited by

                @scottalanmiller

                It works, thaks you.

                scottalanmillerS 1 Reply Last reply Reply Quote 0
                • scottalanmillerS
                  scottalanmiller @iroal
                  last edited by

                  @iroal said:

                  @scottalanmiller

                  It works, thaks you.

                  Thanks for being an early adopter and proof reading my code for me!

                  1 Reply Last reply Reply Quote 0
                  • alex.olynykA
                    alex.olynyk
                    last edited by

                    I created a soft link to /etc/firewalld/zones/public.xml and called it 'fw'

                    But 'fw' is only available from the root directory.

                    How can I make 'fw' available from anywhere on the system?

                    scottalanmillerS 1 Reply Last reply Reply Quote 0
                    • scottalanmillerS
                      scottalanmiller @alex.olynyk
                      last edited by

                      @alex.olynyk said:

                      I created a soft link to /etc/firewalld/zones/public.xml and called it 'fw'

                      But 'fw' is only available from the root directory.

                      How can I make 'fw' available from anywhere on the system?

                      Well a couple of options. But you are kind of thinking of fw as an alias not as a symbolic link.

                      If you wanted a symbolic link that was really handy, you could make it directly under the /. So...

                      ln -s /etc/firewalld/zones/public.xml /fw
                      

                      Then to look at that file you could do...

                      cat /fw
                      less /fw
                      

                      Like that.

                      But likely what you actually want is an alias. What do you want to do with that file? Edit it? If so, use your editor of choice (mine is vi and we will cover why in a later lesson) you could do this...

                      alias fw="vi /etc/firewalld/zones/public.xml"
                      

                      Then when you run fw it opens the file instantly for editing.

                      fw
                      
                      1 Reply Last reply Reply Quote 0
                      • BRRABillB
                        BRRABill
                        last edited by BRRABill

                        Not quite thinking what I was doing, I was trying to forward my /var/log to another folder without delete the original first. Duh.

                        Anyway, I ran this command:

                        ln -s /run/sr-mount/da71e8e4-27b9-f51d-3390-93793b0a2bfd/xenserverlogs /var/log
                        

                        And what it did was put a folder called "xenserverlogs" into the /var/log folder

                        Why did it do that?

                        scottalanmillerS 1 Reply Last reply Reply Quote 0
                        • scottalanmillerS
                          scottalanmiller @BRRABill
                          last edited by

                          @BRRABill said in Linux: Symbolically Linking Files:

                          Not quite thinking what I was doing, I was trying to forward my /var/log to another folder without delete the original first. Duh.

                          Anyway, I ran this command:

                          ln -s /run/sr-mount/da71e8e4-27b9-f51d-3390-93793b0a2bfd/xenserverlogs /var/log
                          

                          And what it did was put a folder called "xenserverlogs" into the /var/log folder

                          Why did it do that?

                          The format is ln -s existingfile linklocation

                          So you designated /run/sr-mount/da71e8e4-27b9-f51d-3390-93793b0a2bfd/xenserverlogs as the existing file. And you told it to make a symbolic link in the /var/log directory. Since /var/log already existed and you didn't specify the name of the symbolic link it had no choice but to use the default which is the "same as the original" which was xenserverlogs. So it created a link from /var/log/xenserverlogs to the file /run/sr-mount/da71e8e4-27b9-f51d-3390-93793b0a2bfd/xenserverlogs.

                          And be sure to never use a term like "forward" in conjunction with links, that's a very different concept and does not apply here. That will just confuse you.

                          BRRABillB 1 Reply Last reply Reply Quote 0
                          • BRRABillB
                            BRRABill @scottalanmiller
                            last edited by

                            @scottalanmiller said

                            So you designated /run/sr-mount/da71e8e4-27b9-f51d-3390-93793b0a2bfd/xenserverlogs as the existing file. And you told it to make a symbolic link in the /var/log directory. Since /var/log already existed and you didn't specify the name of the symbolic link it had no choice but to use the default which is the "same as the original" which was xenserverlogs. So it created a link from /var/log/xenserverlogs to the file /run/sr-mount/da71e8e4-27b9-f51d-3390-93793b0a2bfd/xenserverlogs.

                            And be sure to never use a term like "forward" in conjunction with links, that's a very different concept and does not apply here. That will just confuse you.

                            So to confirm, if I had first removed the /var/log folder, that command would have worked as I wanted it to, correct?

                            scottalanmillerS 1 Reply Last reply Reply Quote 0
                            • scottalanmillerS
                              scottalanmiller @BRRABill
                              last edited by

                              @BRRABill said in Linux: Symbolically Linking Files:

                              So to confirm, if I had first removed the /var/log folder, that command would have worked as I wanted it to, correct?

                              Correct. Since /var/log is a mount point for you, though, that is not as simple as deleting or renaming. You have to stop it mounting first. Then you can rmdir /var/log. Then you can symlink.

                              BRRABillB 1 Reply Last reply Reply Quote 1
                              • 1 / 1
                              • First post
                                Last post