By: Comfortably Anonymous
Times Read: 13,819
Likes: 0 Dislikes: 0
Topic: Linux
Here's one short, really annoyingly hard-to-find command:
ln
The 'ln' command is used to create a symbolic link to another file or directory. The closest thing Windows NT has to it is creating a desktop shortcut to a file or directory. However, 'ln' has a bit more power (I won't go into that part, just type 'man ln' to learn more)
That's all pretty simple, and I can tell that all you experienced Linux people are shaking their heads at this and saying "Like, duh, ya big moron..."
Here's why I am putting this here:
- Get any doc/web page/whatever about how to compile/recompile the Linux kernel. Note that they ALWAYS mention creating a Symbolic Link to a Linuzxxx directory, so that you can then change back to the old if you screw up the compile.
- Get your little install book that came with your Linux install (If you bought it at a store)
- Get a big fat book on Linux. (I went out and bought RedHat Linux: Unleashed)
Note that they ALL talk about Symbolic Links as if they're no big deal and everyone has them (Right next to their opinion, right?)... Also note that there is NOWHERE that tells you how to make a damn Symbolic Link!!! It'll tell you about why you would make one, and where you would make one, but never HOW you would make one! (Linux authors take note of that!!)
RH Linux: Unleashed - It's pathetically hilarious about this (I gotta tell ya about this one...)
OK, in the Index in the back of the book (Always a great place to go in any technical book) it lists Symbolic Link, says see page 643. Cool, so I flip to page 643. This drops me in the Glossary. It has the entry Link, Symbolic. It says:
Directory entry that provides an alias to another file that can be in another filesystem. Multiple entries appear in the directory for one physical file without replication of the contents. Implemented through link files; see also link file.
I look at Link File. It says:
File used to implement a symbolic link producing an alias on one filesystem for a file on another. The file contains only the fully qualified filename of the original (linked-to) file.
There is also an entry for "Link, Soft" which says to see "Link, Symbolic"... (Great help there... Not!)
Nowhere in the whole darn book does it mention that 'ln' is used to actually create these darn link files! After learning from finally asking someone else about how to create a symbolic link, I finally find "ln" at least listed under "File Utilities" on page 352, but that's it. Only a list of the file utility commands (such as ln, cp, rm, mkdir, etc). However, it is NEVER defined.
For lack of this little command, it's very hard to do much advanced stuff in Linux. It kinda reminds me of that story about "for lack of a nail, the kingdom fell"
Oh well, hope this helps somebody out there! :)
By: Comfortably Anonymous
Times Read: 2,664
Likes: 0 Dislikes: 0
Topic: Linux
I am a proud owner of Linux Unleashed who was looking for the link command. I can say, yes, you definately helped me.
By: Comfortably Anonymous
Times Read: 2,738
Likes: 0 Dislikes: 0
Topic: Linux
By: Comfortably Anonymous
Times Read: 2,720
Likes: 0 Dislikes: 0
Topic: Linux
NAME
ln - make links between files
SYNOPSIS
ln [OPTION]... TARGET [LINK_NAME]
ln [OPTION]... TARGET... DIRECTORY
ln [OPTION]... --target-directory=DIRECTORY TARGET...
DESCRIPTION
Create a link to the specified TARGET with optional LINK_NAME. If LINK_NAME is omitted, a link with the same basename as the TARGET is created in the current directory. When using the second form with more than one TARGET, the last argument must be a directory; create links in DIRECTORY to each TARGET. Create hard links by default,
symbolic links with --symbolic. When creating hard links, each TARGET must exist.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL]
make a backup of each existing destination file
-b like --backup but does not accept an argument
-d, -F, --directory
hard link directories (super-user only)
-f, --force
remove existing destination files
-n, --no-dereference
treat destination that is a symlink to a directory as if it were a normal file
-i, --interactive
prompt whether to remove destinations
-s, --symbolic
make symbolic links instead of hard links
-S, --suffix=SUFFIX
override the usual backup suffix
--target-directory=DIRECTORY
specify the DIRECTORY in which to create the links
-v, --verbose
print name of each file before linking
--help display this help and exit
--version
output version information and exit
The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values:
none, off
never make backups (even if --backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple otherwise
simple, never
always make simple backups
AUTHOR
Written by Mike Parker and David MacKenzie.
REPORTING BUGS
Report bugs to
COPYRIGHT
Copyright ⌐ 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
SEE ALSO
The full documentation for ln is maintained as a Texinfo manual. If the info and ln programs are properly installed at your site, the command
info ln
should give you access to the complete manual.
By: Comfortably Anonymous
Times Read: 7,046
Likes: 0 Dislikes: 0
Topic: Linux
Using the '-s' option requires you to know the difference between a 'hard link' and a 'symlink':
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. On all existing implementations, you cannot make a hard link to a
directory, and hard links cannot cross filesystem boundaries. (These restrictions are not mandated by POSIX, however.)
"Symbolic links" ("symlinks" for short), on the other hand, are a special file type in which the link file actually refers to a different file, by name. When most operations (opening, reading, writing, and so on) are passed the symbolic link file, the kernel automatically "dereferences" the link and operates on the target of the link. But some operations (e.g., removing) work on the link file itself, rather than on its target.
In other words, a symlink is just a pointer to a file. Say you have a simlink /home/myname/somefile.txt which actually points to /home/yourname/textfiles/yourfile.txt. If you bring up /home/myname/somefile.txt in an editor, you are actually editing the /home/yourname/textfiles/yourfile.txt file, even though it looks to you like you are editing /home/myname/somefile.txt. If you have a symlink pointing to an executable file, then the executable file will run if you type the name of the symlink.
Here's the biggest and most dangerous difference between a hardlink and a symlink: If you delete a symlink, you only delete the pointer to the actual file. However, if you have a hard link /home/myname/hardlink.txt "pointing" to /home/myname/importantinfo.txt and you delete /home/myname/hardlink.txt, you ALSO DELETE /home/myname/importantinfo.txt!! Be careful, a hard link can burn you.
Weirdly, only the root user can create a symlink. Any user can create a hard link. I still haven't figured that one out. If someone knows why, please reply to this message and let me know! :)
Another bit of lore about ln -s:
To make a symlink from /home/myname/some/directory/pointerfile to /usr/local/something/configfile, it's a lot easier to change to the directory where the pointerfile is going to live before creating the link. Otherwise you have to play a lot of weird games to get the link name right.
For example:
cd /home/myname/some/directory
ln -s /home/myname/otherdir/configfile pointerfile
That will create a symlink pointing to /home/myname/otherdir/configfile in the directory /home/myname/some/directory called pointerfile.
However, if you try this instead:
cd /home/myname
ln -s ./some/directory/configfile ./otherdir/pointerfile
You'd think you'd end up with the same thing as in the first example. However, it doesn't work right. If you do an
ls -l ./otherdir
You will see a broken symlink pointing to a non-existent location of "./some/directory/configfile". Note that the current directory symbol './' is not interpreted, it is tacked on literally to the simlink name.
Enough for now, any questions, just reply to this message!
By: Comfortably Anonymous
Times Read: 2,115
Likes: 0 Dislikes: 0
Topic: Linux
I was looking for that command too. My books were no use. I did a search on Google and found your post.
Symbolic link has now been created on my server and I am a happy bunny. I think that people who write about Linux are often so close to it, they don't realise what things may not be obvious to new users.
Caroline
By: Comfortably Anonymous
Times Read: 2,173
Likes: 0 Dislikes: 0
Topic: Linux
I've just reinstalled linux (been windows only since 1999) and I couldn't remember the command.. I knew it was called a symbolic link without reading it anywhere, but I just couldn't for the life of me rembember those two letters.. :)
BTW: Great fun reading the text... I know how you must have felt.
regards,
a renewbie
By: Comfortably Anonymous
Times Read: 2,103
Likes: 0 Dislikes: 0
Topic: Linux
I first had to figure out how those things were called.
After the man-page of ln 'mc' helped me out. (Another 2 letter command that is very useful.