89 lines
4.4 KiB
HTML
89 lines
4.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Converted with LaTeX2HTML 95.1 (Fri Jan 20 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE>3.10.1 Hard links</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value="3.10.1 Hard links">
|
|
<meta name="keywords" value="gs">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html3400 HREF="node131.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME=tex2html3398 HREF="node129.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME=tex2html3392 HREF="node129.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME=tex2html3402 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <A NAME=tex2html3403 HREF="node250.html"><IMG ALIGN=BOTTOM ALT="index" SRC="index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3401 HREF="node131.html">3.10.2 Symbolic links</A>
|
|
<B>Up:</B> <A NAME=tex2html3399 HREF="node129.html">3.10 Managing file links</A>
|
|
<B> Previous:</B> <A NAME=tex2html3393 HREF="node129.html">3.10 Managing file links</A>
|
|
<BR> <HR> <P>
|
|
<H2><A NAME=SECTION005101000000000000000>3.10.1 Hard links</A></H2>
|
|
<P>
|
|
<A NAME=3304> </A>
|
|
The <tt>ln</tt> command is used to create multiple links for one
|
|
file. For example, let's say that you have the file <tt>foo</tt> in
|
|
a directory. Using <tt>ls -i</tt>, we can look at the inode number
|
|
for this file.
|
|
<P><TT> # <em>ls -i foo</em> <BR>
|
|
22192 foo <BR>
|
|
#
|
|
<P></TT>
|
|
Here, the file <tt>foo</tt> has an inode number of 22192 in the
|
|
filesystem. We can create another link to <tt>foo</tt>, named <tt>bar</tt>:
|
|
<P><TT> # <em>ln foo bar</em>
|
|
<P></TT>
|
|
With <tt>ls -i</tt>, we see that the two files have the same inode.
|
|
<P><TT> # <em>ls -i foo bar</em> <BR>
|
|
22192 bar 22192 foo <BR>
|
|
#
|
|
<P></TT>
|
|
Now, accessing either <tt>foo</tt> or <tt>bar</tt> will access
|
|
the same file. If you make changes to <tt>foo</tt>, those changes
|
|
will be made to <tt>bar</tt> as well. For all purposes, <tt>foo</tt>
|
|
and <tt>bar</tt> are the same file.
|
|
<P>
|
|
These links are known as <em>hard links</em> because they directly
|
|
create a link to an inode. Note that you can only hard-link files on
|
|
the same filesystem; symbolic links (see below) don't have this
|
|
restriction.
|
|
<P>
|
|
When you delete a file with <tt>rm</tt>, you are actually only
|
|
deleting one link to a file. If you use the command
|
|
<P><TT> # <em>rm foo</em>
|
|
<P></TT>
|
|
then only the link named <tt>foo</tt> is deleted; <tt>bar</tt>
|
|
will still exist. A file is only actually deleted on the system
|
|
when it has no links to it. Usually, files have only one
|
|
link, so using the <tt>rm</tt> command deletes the file. However,
|
|
if a file has multiple links to it, using <tt>rm</tt> will only
|
|
delete a single link; in order to delete the file, you must
|
|
delete all links to the file.
|
|
<P>
|
|
<A NAME=3336> </A>
|
|
The command <tt>ls -l</tt> will display the number of links to a
|
|
file (among other information).
|
|
<P><TT> # <em>ls -l foo bar</em> <BR>
|
|
<code>-rw-r--r-- 2 root root 12 Aug 5 16:51 bar</code> <BR>
|
|
<code>-rw-r--r-- 2 root root 12 Aug 5 16:50 foo</code> <BR>
|
|
#
|
|
<P></TT>
|
|
The second column in the listing, ``<tt>2</tt>'', specifies the number of
|
|
links to the file.
|
|
<P>
|
|
As it turns out, a directory is actually just a file containing information
|
|
about link-to-inode translations. Also, every directory has at least two
|
|
hard links in it: ``<tt>.</tt>'' (a link pointing to itself), and
|
|
``<tt>..</tt>'' (a link
|
|
pointing to the parent directory). The root directory (<tt>/</tt>)
|
|
``<tt>..</tt>'' link
|
|
just points back to <tt>/</tt>.
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html3400 HREF="node131.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME=tex2html3398 HREF="node129.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME=tex2html3392 HREF="node129.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME=tex2html3402 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <A NAME=tex2html3403 HREF="node250.html"><IMG ALIGN=BOTTOM ALT="index" SRC="index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3401 HREF="node131.html">3.10.2 Symbolic links</A>
|
|
<B>Up:</B> <A NAME=tex2html3399 HREF="node129.html">3.10 Managing file links</A>
|
|
<B> Previous:</B> <A NAME=tex2html3393 HREF="node129.html">3.10 Managing file links</A>
|
|
<BR> <HR> <P>
|
|
<BR> <HR>
|
|
<P><ADDRESS>
|
|
<I>Matt Welsh <BR>
|
|
mdw@sunsite.unc.edu</I>
|
|
</ADDRESS>
|
|
</BODY>
|