pavement

Shortcuts

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (style consistency)
Line 1: Line 1:
 
In the Unixlike world, MS Windows' "shortcuts" are replaced with sym[[links]].  Links are, however, considerably more powerful than shortcuts - a shortcut is only useful in certain situations, such as double-clicking on it directly to execute it, while a symlink can be used as an actual reference for the file itself - for example if you make a symlink of the directory '''/home/original''' at '''/home/symlink''', you can actually save a file to '''/home/symlink/newfile''' and it will arrive properly in the real directory, '''/home/original'''.
 
In the Unixlike world, MS Windows' "shortcuts" are replaced with sym[[links]].  Links are, however, considerably more powerful than shortcuts - a shortcut is only useful in certain situations, such as double-clicking on it directly to execute it, while a symlink can be used as an actual reference for the file itself - for example if you make a symlink of the directory '''/home/original''' at '''/home/symlink''', you can actually save a file to '''/home/symlink/newfile''' and it will arrive properly in the real directory, '''/home/original'''.
  
  ph34r# '''cd /home'''
+
  samizdata# '''cd /home'''
  ph34r# '''mkdir original'''
+
  samizdata# '''mkdir original'''
  ph34r# '''ln -s original symlink'''
+
  samizdata# '''ln -s original symlink'''
  ph34r# '''ls -l'''
+
  samizdata# '''ls -l'''
 
  lrwxr-xr-x  1 jimbo            wheel            6 Dec 18 10:53 symlink -> original
 
  lrwxr-xr-x  1 jimbo            wheel            6 Dec 18 10:53 symlink -> original
 
  drwxr-xr-x  18 jimbo            wheel          512 Jun 19 20:48 original
 
  drwxr-xr-x  18 jimbo            wheel          512 Jun 19 20:48 original
Line 10: Line 10:
 
See the symlinked directory?  Note that the real directory has a "d" in the front of the file permissions section (drwxr-xr-x) while the symlink has an "l" there (lwrxr-xr-x).  Also note that the name section of the symlink includes a visual pointer showing you where the symlink ''really'' goes - to the directory '''original''', in this case.
 
See the symlinked directory?  Note that the real directory has a "d" in the front of the file permissions section (drwxr-xr-x) while the symlink has an "l" there (lwrxr-xr-x).  Also note that the name section of the symlink includes a visual pointer showing you where the symlink ''really'' goes - to the directory '''original''', in this case.
  
  ph34r# '''echo "hello" > symlink/newfile'''
+
  samizdata# '''echo "hello" > symlink/newfile'''
  ph34r# '''cat original/newfile'''
+
  samizdata# '''cat original/newfile'''
 
  "hello"
 
  "hello"
  ph34r# '''cat jimbo/newfile'''
+
  samizdata# '''cat jimbo/newfile'''
 
  "hello"
 
  "hello"
  

Revision as of 17:45, 16 May 2006

In the Unixlike world, MS Windows' "shortcuts" are replaced with symlinks. Links are, however, considerably more powerful than shortcuts - a shortcut is only useful in certain situations, such as double-clicking on it directly to execute it, while a symlink can be used as an actual reference for the file itself - for example if you make a symlink of the directory /home/original at /home/symlink, you can actually save a file to /home/symlink/newfile and it will arrive properly in the real directory, /home/original.

samizdata# cd /home
samizdata# mkdir original
samizdata# ln -s original symlink
samizdata# ls -l
lrwxr-xr-x   1 jimbo             wheel            6 Dec 18 10:53 symlink -> original
drwxr-xr-x  18 jimbo             wheel          512 Jun 19 20:48 original

See the symlinked directory? Note that the real directory has a "d" in the front of the file permissions section (drwxr-xr-x) while the symlink has an "l" there (lwrxr-xr-x). Also note that the name section of the symlink includes a visual pointer showing you where the symlink really goes - to the directory original, in this case.

samizdata# echo "hello" > symlink/newfile
samizdata# cat original/newfile
"hello"
samizdata# cat jimbo/newfile
"hello"

And here's the proof of how well symlinks work as referential pointers - when we create a file "in" the symlink, it actually shows up in the real directory that the symlink pointed to... and whether we attempt to read that file from "inside" the symlink or the real directory, it shows up equally well either way.

See also Links for information on how hard links as well as soft links actually work within the filesystem, and/or ln for more examples of the syntax of the ln command itself.

Personal tools