Thursday, February 27, 2014

Symbolic links in Unix-like OSs

In Unix-like systems, if you have a command-line app, and you want to run it, you will have to type its full address in the terminal, like this
/Users/name/myFolder/app
Or you can navigate to its folder with cd /Users/name/myFolder and then use ./app to run it.

Another way would be to move that application to a folder that is in the system's $PATH . But if you don't want to move the application (and assuming you don't want to change your $PATH either), then you can add a shortcut for your application to a folder that is included in $PATH . To see the list of these folders, type
echo $PATH
and then pick one of the folders displayed. For example, /usr/local/bin . Now we will add a symbolic link (like a shortcut) to our application in this folder. This can be done by
ln -s /Users/name/myFolder/app /usr/local/bin

Perfect! now you can run your app by simply typing app in any terminal! (Of course, app should be the specific name of your app.)

No comments:

Post a Comment