Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Linux / UNIX and the fly likes Symbolic Links for executables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Symbolic Links for executables" Watch "Symbolic Links for executables" New topic
Author

Symbolic Links for executables

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

What are these symbolic links actually? As I was reading through a book for the Linux+ certification, it is stated that the executable for the vi editor is actually placed under the /bin directory and a symbolic link is located under /usr/bin/ directory which in turn points to the executable located under /bin? What does this symbolic link mean?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Jothi,

symbolic links in UNIX/Linux work basically like shortcuts in Windows. You can create an alias for a file or directory at a different location instead of creating a physical copy of the file or directory. For your example this means that you only have to maintain one copy of the vim executable but the use can find vim in both mentioned directories because the second one is a link to the first one ;-)

Marco
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

No, they don't work like .lnk-Files in Windows. (or is "shortcut" something new?)

a) Are symbolic links older than Windows-links, so if at all Windowslinks work like the unix ones. But they don't. b) A windows-link is a file which contains the information to where it links, while symbolic links on linux are a concept of the filesystem.

If you copy a symbolic link on windows to your USB-Stick, and try to use it later, you will be frustrated - it is just the .lnk-File, not the file it should link to.

The linux/unix link is much more useful, i.E. the link behaves as if it where the original file. It just doesn't consume the diskspace - it's like a reference or an pointer to an somewhere else specified object.


http://home.arcor.de/hirnstrom/bewerbung
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

No, with shortcuts I meant the same as .lnk files. Not sure how they are called in English but I think it was shortcut.

And sorry for not going into details for the sake of an easy to understand answer. Of course symbolic links in UNIX are not the same as those Windows shortcuts because the whole organization of the file system works differently. I just said they basically work like the said shortcuts. I know that a lot of Linux commands let you choose if a symbolic link itself is copied/moved/etc. or the file it references, but I thought these details wouldn't make it easier for Jothi to understand what symbolic links are. Everyone working with Linux will soon realize that there are many more things regarding the file system which work different than on Windows.

Although I'm aware of the fact that UNIX-like systems were there long before Windows was invented. In fact it's interesting how many internal concepts in a modern Windows OS are very similar to those that have been used in UNIX systems many years before.


Marco
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Thanks guys!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

There are 2 ways that symbolic links are useful in Linux (and the other *n*x OS's) for executing programs.

1. As a simple alias. For example, people are used to invoking "vi", but there are actually a number of vi-like editors out there. Often the "vi" on a Linux system is really vim. But since "vi" is the generic name, it makes life (and how-to books) easier to alias "vi" to be a shortcut to starting vim. A lot of people don't even realize they're not really runnin vi until they encounter a system where "vi" brings up the real vi. Likewise, some systems allow you to invoke Perl as either /usr/bin/perl or /bin/perl.

2. As a convenience feature. A good example is the ldapmodify prorgam. It has an alias of "ldapadd". When you run this utility, the startup code looks at the name you used. If you started it using the "ldapadd" name, the add mode features are automatically switched on.

Perhaps the most extreme example of aliasing is the BusyBox utility. BusyBox is an all-in-one program that provides the basic functions of a host of Unix utilities. It's intended for use in settting up minimal systems where disk space may be limited, and it allows you to install them all by copying a single file. A lot of Unix utilities have common functionalities, so you can save significantly by only having one copy of them.

So when you invoke grep, you run BusyBox and it runs its grep utility. Invoke it from the sed alias, you get sed, and so forth.


Customer surveys are for companies who didn't pay proper attention to begin with.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Symbolic links on linux are not limited to executable programs. You may put a symbolic link to an image, a soundfile, a directory, and so on.

Afaik, lnk-files are very limited on Windows. Can you open an Image-LNK with MS-Gimp? Step into a directory?
 
wood burning stoves
 
subject: Symbolic Links for executables
 
Similar Threads
going nuts trying to reference images on server
Jar Files: Kill me NOW.
What do I need to know about Java and OS X?
NoClassDefFoundError: HttpServlet
installing java on fedora