| Author |
Topic  |
|
|
Dichter
BIAC Faculty
   
190 Posts |
Posted - Jun 20 2007 : 09:19:01 AM
|
In Golgi, to create a symbolic link to a folder, type:
ln -s ~/net/goldman/data/BIAC/DepTher.02/Scripts/ ./blah (or whatever you want to call it)
After that, to change directories to the above folder, you only need to type:
cd blah
|
Gabriel S. Dichter, PhD UNC Departments of Psychiatry & Psychology http://www.can.unc.edu/ |
|
|
vinod
Average Member
  
USA
68 Posts |
Posted - Jun 20 2007 : 09:25:58 AM
|
| How is this different from just using an 'alias'? Are there any advantages to ln over alias? |
 |
|
|
Dichter
BIAC Faculty
   
190 Posts |
Posted - Jun 20 2007 : 09:28:21 AM
|
I don't know - I noticed that few folks knew about this time-saver, so I thought I'd post it. Could you post the usage of an alias? A draw-back of the symbolic link is that you cannot go up one level from the symbolic link... rather you wind up back where you started when you use "cd .." . |
Gabriel S. Dichter, PhD UNC Departments of Psychiatry & Psychology http://www.can.unc.edu/ |
 |
|
|
syam.gadde
BIAC Staff
    
USA
421 Posts |
Posted - Jun 20 2007 : 10:02:11 AM
|
Symbolic links are just pointers to target files or directories, that programs will usually use as if they were the real target files or directories. (Similar to, but more functional than, "shortcuts" on Windows) You may find, however, that the CIFS-mounted storage servers (this includes everything except hodgkin, huxley and katz) on golgi will not support the creation of symbolic links (though any of them could be the target of a symbolic link that is stored on a file system that does support symbolic links). This generally means symbolic links on golgi will only work when pointing "from" a local filesystem like your golgi home directory or /data/users. But they can be very useful nonetheless.
Aliases are something very different. They are shell command substitutions, so if you set up an alias like this:
alias editor=nedit
Typing "editor myfile" will be the same as typing "nedit myfile". These can get more complex. |
 |
|
|
josh.bizzell
BIAC Staff
   
USA
118 Posts |
Posted - Jun 20 2007 : 10:03:11 AM
|
A symbolic link is basically just like a file/folder "shortcut" in Windows. So, you can create a symbolic link to any file or folder in any other folder you'd like.
An alias is used to make shortcuts to commands. Thus, it can be used just like "ln" (e.g. using the "cd" command), but it also can be used for commands that you always use. For example, if you always type:
$ matlab -nojvm -nodisplay You could set the command "matlab" to be that command using an alias that has been defined in your .bash_profile (or .cshrc, .tcshrc, etc...) file:
alias matlab = 'matlab -nojvm -nodisplay' So now, whenever you type "matlab" on the command line, it will run matlab with the -nojvm and -nodisplay flags already set.
Edit: Syam beat me by a minute. :) |
Edited by - josh.bizzell on Jun 20 2007 10:05:01 AM |
 |
|
|
jim.voyvodic
BIAC Faculty
   
138 Posts |
Posted - Jun 20 2007 : 10:41:45 AM
|
I use aliases all the time. Things like:
alias golgi='ssh -X voyvodic@golgi.biac.duke.edu' alias BIRN30='cd /mnt/users/jim/adrian/data2/BIRN.30'
then I can just type: golgi and it asks me for my password and I log in to Golgi. Or type: BIRN30 and voila, I have changed directories to BIRN.30 on Adrian. Set these up in your .bashrc file and they're always defined. It beats typing.
Jim
|
 |
|
|
deshmukh
BIAC Alum
 
40 Posts |
Posted - Jun 20 2007 : 11:33:05 AM
|
A word of caution about links. It's important to use the "-s" while creating a link. This sets it up as "symbolic" i.e. if you delete the link, the file that it points to is not deleted. Eg: #Create a symbolic link ln -s myfile linkto_myfile #Deleting the symbolic link does not delete the file rm linkto_myfile
#Create a hard link (no -s option) ln myfile linkto_myfile #Deleting the hard link deletes the file rm linkto_myfile
|
 |
|
|
jim.voyvodic
BIAC Faculty
   
138 Posts |
Posted - Jun 20 2007 : 11:48:06 AM
|
A minor point, deleting a hard link does not delete the file unless the original filename has already been deleted. In fact, by creating a hard link you can no longer delete the file unless you delete the link itself. The original filename is a hard link to the data, and if you create a hard link to that file you are actually creating a link to the data itself (not to the original filename). There is no difference between the original name and the link name. To actually delete the data you would have to delete both links to it (the last link to go actually frees up the disk space).
A soft link is a pointer the the original filename (like a Windows shortcut). If you delete the link you just lose the pointer. If you delete the original filename you delete the data; the link can remain, but now it points to a non-existent file.
I am actually quite fond of hard links and find that they can be very useful, so as long as we are talking about links we may as well be accurate.
In general, using aliases or setting environment variables is a more flexible way to create shortcuts than using links. But aliases and environment variables need to be put into the login startup file (.bashrc) and are user specific.
The advantages of using links is that they are disk-based, so they persist across login sessions and are available to any user with access to those files.
Jim |
 |
|
| |
Topic  |
|