hard links, soft links

Place to discuss Slackware
Post Reply
worker201
guru
guru
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii

hard links, soft links

Post by worker201 » Sun Jul 15, 2007 11:08 pm

In Slackware, the vi is a link to elvis. I don't care much for elvis, or the way it handles the backspace character - I'd much rather use vim. I guess the thing to do is relink it, but I can't tell if it is a symbolic link or a hard link. How do you tell? As a matter of fact, I've never actually messed with hard links before, only soft links, so I'm not sure on the difference or the proper usage of both.

Here's what I see on my computer:

Code: Select all

ls /usr/bin vi* -l
lrwxrwxrwx 1 root root         5 2007-06-27 07:54 vi -> elvis
lrwxrwxrwx 1 root root         3 2007-06-27 07:55 view -> vim
-rwxr-xr-x 1 root root   3439500 2006-09-17 20:03 vim
lrwxrwxrwx 1 root root         3 2007-06-27 07:55 vimdiff -> vim
-rwxr-xr-x 1 root root      1600 2006-09-17 20:03 vimtutor
I guess what I want to know is, do I do:

Code: Select all

ln vim vi
or:

Code: Select all

ln -s vim vi
?
(or do I even have that backwards?)

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Jul 16, 2007 6:42 am

It's a symbolic link and you have the syntax right although unless you first delete the link you'll have to also add the '-f' parameter:

Code: Select all

# cd /usr/bin
# ln -sf vim vi
or

Code: Select all

# cd /usr/bin
# rm vi
# ln -s vim vi
Or you could leave it and create an alias in your ~/.bashrc

Code: Select all

alias vi='vim'
One way you can tell if it's a symbolic link is when you do an "ls -l /usr/bin/vi" you will see the name of the link (vi) and the actual program or link that it points to after the "->" symbol. A hard link look just like any other normal file. The only way you can tell if something is a hard link to something else is to look at their inode number. You can see inode numbers if you add a "-i" switch to "ls" and you can search for files with a specific inode using the 'find' command with the '-inum' parameter. Also "ls -l" shows the number of links a file has which

worker201
guru
guru
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii

Post by worker201 » Mon Jul 16, 2007 11:24 am

Is there any reason to favor one method over the other in a single-user environment? I could see how using an alias would be good on a multi-user terminal. But it's just me and root in here. An alias for both, or a symlink for everyone, what's the difference? Perhaps since it is my system, and I can't stand elvis, the symlink is the way to go.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Jul 16, 2007 11:46 am

It's whatever works for you. Sounds like the symbolic link is the way to go for you. I would probably also just uninstall elvis if it's not needed by some other Slackware package.

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Mon Jul 16, 2007 3:03 pm

Does slackware use any alternatives system like fedora and debian do? That will automatically put links like that in. And it will keep doing it unless you use that system to remove it.

Also, the only reason i can think of using hardlinks is to link to a specific file to save disk space and keep changes across (transaparently so it doesnt act like a symlink). The permissions work differently too. I cant remember if they're associated with inode number or each file (hardlink).

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Jul 16, 2007 3:38 pm

I think he was referring to alias vs link rather than symbolic link vs hard link. At any rate regardless of the type the permissions aren't handled any differently. The main purpose of the symbolic link is so you can link to another file on another file system. Hard links can not cross file systems. The symbolic link does require another inode where a hard link shares the same inode which is another main difference. In both cases there is only one single copy of the data so neither takes up any more room than the other, just one requires an extra inode from the inode table as I said.

worker201
guru
guru
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii

Post by worker201 » Mon Jul 16, 2007 10:36 pm

To put a closer on this topic, I deleted the current elvis-vi and symlinked it to vim. Worked like a charm. The difference was immediate, too - vim color-codes code by default, looks much nicer. And the backspace key doesn't drop characters into the 7th dimension.

User avatar
Calum
guru
guru
Posts: 1349
Joined: Fri Jan 10, 2003 11:32 am
Location: Bonny Scotland
Contact:

Post by Calum » Thu Jul 19, 2007 9:37 am

i was under the impression that apps like vim and elvis will run differently re: things like colour coding depending on how they are invoked, ie: if invoked through a symlink called "vi" they would behave differently than if called directly. Is this a misunderstanding on my part?

also, why not put the alias into a global rc file? something like /etc/profile or maybe there's an /etc/bashrc to put it into. This is probably what i'd do after reading this thread, simply because i like to treat any system as though it's a multiuser system, because i think that's good practice and aolso you never know what the future holds.

worker201
guru
guru
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii

Post by worker201 » Thu Jul 19, 2007 12:20 pm

Calum wrote:i was under the impression that apps like vim and elvis will run differently re: things like colour coding depending on how they are invoked, ie: if invoked through a symlink called "vi" they would behave differently than if called directly. Is this a misunderstanding on my part?

I did some quick research into this. They do have command-line options, which are mostly for file management. Command-line arguments are clearly passed to the editor, otherwise I couldn't tell it what file to open - "vi myfile.txt" works whether you use a symlink or an alias. It looks like both vim and elvis use an rc script such as .vimrc to control their environment, although there are also commands within both programs to change environment settings on the fly.
Calum wrote:also, why not put the alias into a global rc file? something like /etc/profile or maybe there's an /etc/bashrc to put it into. This is probably what i'd do after reading this thread, simply because i like to treat any system as though it's a multiuser system, because i think that's good practice and aolso you never know what the future holds.
You're probably right, pretending it is a multiuser system is better for learning, which is my primary goal. But I don't think there is any real difference between using a symlink or a global alias. In fact, you could probably use both. A symlink is what was there, so that's what I worked with. (the fact that the symlink was to elvis, not vim, was probably Pat's personal choice) I believe that any user could still make a local alias to choose another editor. I'll actually try using both a global symlink and a local alias to see which editor I get, just so I know how it works.

Post Reply