pavement

Shortcuts

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
m (style consistency)
m (Found this page on Random pick, added link to the ln article.)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
 +
''The concepts noted in this article are documented within the [[ln]] article.''
 +
 
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'''.
  
  samizdata# '''cd /home'''
+
  ph34r# '''cd /home'''
  samizdata# '''mkdir original'''
+
  ph34r# '''mkdir original'''
  samizdata# '''ln -s original symlink'''
+
  ph34r# '''ln -s original symlink'''
  samizdata# '''ls -l'''
+
  ph34r# '''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 12:
 
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.
  
  samizdata# '''echo "hello" > symlink/newfile'''
+
  ph34r# '''echo "hello" > symlink/newfile'''
  samizdata# '''cat original/newfile'''
+
  ph34r# '''cat original/newfile'''
 
  "hello"
 
  "hello"
  samizdata# '''cat jimbo/newfile'''
+
  ph34r# '''cat jimbo/newfile'''
 
  "hello"
 
  "hello"
  

Latest revision as of 17:10, 5 May 2008

The concepts noted in this article are documented within the ln article.

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.

ph34r# cd /home
ph34r# mkdir original
ph34r# ln -s original symlink
ph34r# 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.

ph34r# echo "hello" > symlink/newfile
ph34r# cat original/newfile
"hello"
ph34r# 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