Linux: Symbolically Linking Files
-
It's Centos 7, spanish. let my know if you need any test.
-
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
-
It works, thaks you.
-
@iroal said:
It works, thaks you.
Thanks for being an early adopter and proof reading my code for me!
-
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?
-
@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
-
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?
-
@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.
-
@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?
-
@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.