Click to See Complete Forum and Search --> : Creating a symlink from the command prompt
JavaCowboy
06-13-2001, 09:34 PM
I know how to do it from a Nautilus or File Manager window, but I'd like to learn how to create a symlink from the command prompt.
I had to create one that required root permission, and ended up logging on to GNOME as root. Needless to say, I'd rather just open a command prompt and do an su in that situation.
ph34r
06-13-2001, 09:36 PM
ln -s /file/that/is/already/there /name/and/location/of/new/sym/link
JavaCowboy
06-13-2001, 09:49 PM
Originally posted by ph34r:
<STRONG>ln -s /file/that/is/already/there /name/and/location/of/new/sym/link</STRONG>
Thanks for the tip. BTW, what's the difference between a symbolic link and a hard link?
Linuxcool
06-13-2001, 10:47 PM
Let's see if I can explain this.
A symbolic link:
1) creates a small file that contains information about where the file, that it is pointing to, is located .
2) can point to a non-existing file.
3) it has a different inode number than the file it points to.
A hard link:
1) doesn't create a file.
2) cannot point to a non-existing file.
) it has the same inode number as the file it points to. In other words, it points to the same information block as the original file name entry.
X_console
06-13-2001, 11:38 PM
In addition to what was said, a symlink can span multiple partitions, but a hardlink can't. So that means if /usr/local/bin/foobar is on a separate partition, and you want to create a link to it in /bin which is another partition, then you need to use a symlink. If you try to create a hardlink, it will fail.
Craig McPherson
06-14-2001, 12:17 AM
A symlink is like a "Shortcut" in Windows 95. Golly, did Linux steal an idea from Bill Gates? No, Bill Gates stole an idea from UNIX.
A hard link is when one single file on the disk has multiple filenames. Multiple filenames, but they're all the exact same file on disk. As such, they have to be on the same filesystem. Deleting a hardlinked file really junk unlinks the filename from the file on disk. It's impossible to actually delete anything directly in UNIX: you can only unlink filenames from files, and if a file on disk has zero filenames linked to it, it'll be deleted automatically by the kernel.
Never create a hard link to a directory. If you do, you'll be up all night fixing your filesystem, or so O'Reilly says: I've never done it.