next up previous
Next: Directories That Aren't Directories Up: Introduction to the Linux Previous: File Archiving and Compression

Files That Aren't Files

Sometimes a file is squirrelled away somewhere and we'd rather not have to keep typing a laborious path to get to it. One way around this is to use a link. The link command, ln -s, works is a similar way to the copy command cp except that instead of making a copy of the file, it makes what is called a symbolic link. The difference between a link and a copy is that if you edit a file, all of the links are changed as well; if you copy a file and edit it, then of course only that copy changes.

[phasnip@mijpnb1 ~]$ ln -s Teaching/Linux/linux.tex .

Be warned that Linux does not check that the actual file exists until you try to do something with it. This can be quite useful, but can also lead to confusion.

Links have an `@' sign appended to their filenames when you do ls -F, and if you do ls -l you'll see their type is listed as l and Linux shows where the link points to.

[phasnip@mijpnb1 ~]$ ls -F
a.out*            ifort@         minimiser.dvi   quality.sty  test.F90
castep_CVS.tar    junk           minimiser.log   Rules/       tmp/
Data/             linux.tex@     minimiser.tex   t
Desktop/          list           minimiser.tex~  t~
hermes.addresses  minimiser.aux  Nautilus/       Teaching/

[phasnip@mijpnb1 ~]$ ls -l li*
lrwxrwxrwx    1 phasnip  phasnip        24 Oct 17 22:37 linux.tex -> Teaching/Linux/linux.tex
-rw-rw-r--    1 phasnip  phasnip        75 Oct 18 01:06 list

Please note than you can create different types of links, but you will almost certainly always want symbolic link, so always use ln with the -s switch.


next up previous
Next: Directories That Aren't Directories Up: Introduction to the Linux Previous: File Archiving and Compression
Phil Hasnip 2007-08-23