pavement

Shortcuts

From FreeBSDwiki
Jump to: navigation, search

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