old-www/LDP/LG/issue39/tag/5.html

183 lines
6.7 KiB
HTML

<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<META NAME="generator" CONTENT="lgazmail v1.1J.c">
<TITLE>The Answer Guy 39: Deleting Files and UNIX Permissions</TITLE>
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000"
LINK="#3366FF" VLINK="#A000A0">
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<H4>"The Linux Gazette...<I>making Linux just a little more fun!</I>"</H4>
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<center>
<H1><A NAME="answer">
<img src="../../gx/dennis/qbubble.gif" alt="(?)"
border="0" align="middle">
<font color="#B03060">The Answer Guy</font>
<img src="../../gx/dennis/bbubble.gif" alt="(!)"
border="0" align="middle">
</A></H1>
<BR>
<H4>By James T. Dennis,
<a href="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</a><BR>
LinuxCare,
<A HREF="http://www.linuxcare.com/">http://www.linuxcare.com/</A>
</H4>
</center>
<p><hr><p>
<!-- endcut ======================================================= -->
<!-- begin 5 -->
<H3 align="left"><img src="../../gx/dennis/qbubble.gif"
height="50" width="60" alt="(?) " border="0"
>Deleting Files and UNIX Permissions</H3>
<p><strong>From martin a. salazar on Fri, 05 Mar 1999
</strong></p>
<!-- ::
Deleting Files and UNIX Permissions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: -->
<P><STRONG><IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
Hi,
</STRONG></P>
<P><STRONG>
How can I delete files with attributes like these.
</STRONG></P>
<Pre><STRONG>
b---r----- 1 10080 24640 96, 68 Feb 10 1977 csh.cshrc
b---rwxr-- 1 24672 8231 32, 39 Dec 16 2010 exports
</STRONG></Pre>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
These look CORRUPT. See below.
</BLOCKQUOTE>
<P><STRONG><IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
Regards,
<br>Marty Salazar
</STRONG></P>
<BLOCKQUOTE><IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
HEIGHT="28" WIDTH="50" BORDER="0"
>
Your ability to remove files has nothing to do with
the permissions of the files themselves, and often
nothing to do with the ownership of the files.
</BLOCKQUOTE>
<BLOCKQUOTE>
Under UNIX (and Linux, of course) you need write access
to the <EM>directory</EM> in which a link occurs to remove that
link. So in a mode 777 directory you can remove <EM>any</EM>
filename (link) REGARDLESS OF WHO OWNS THAT FILE AND
REGARDLESS OF THE PERMISSIONS ON IT.
</BLOCKQUOTE>
<BLOCKQUOTE>
(As a special case under Linux and most modern versions
of Unix if the mode of the directory is "sticky" ---
mode 1xxx --- then you must have write access to the
directory <EM>and</EM> you must own the file, or be root, to
unlink/remove it).
</BLOCKQUOTE>
<BLOCKQUOTE>
Note that I've made a distinction here between the file
and its names (links). In a Unix/Linux filesystem a
file is an association between an inode (a management and
meta-data structure) and a set of data blocks (the
data or file contents). The file's <EM>name</EM> is a link from
a directory to the inode. There can be many such links
or "hard links.
</BLOCKQUOTE>
<BLOCKQUOTE>
Thus the process of removing a file involves "unlinking"
it. When the link count is zero (there are no remaining
links to a file) and there are not processes with a
file open, then the filesystem driver removes the actual
file (that is it marks the inode as deleted and adds
all of its data blocks back to the "free" list.
</BLOCKQUOTE>
<BLOCKQUOTE>
So the '<tt>rm</tt>' command doesn't actually "remove files" ---
technically it "unlinks files from directories" (which
often has the side effect of reducing the link count to
zero and consequently deleting the file).
</BLOCKQUOTE>
<BLOCKQUOTE>
Understanding this hopefully explains why write access
to a directory is generally sufficient to remove files
in it.
</BLOCKQUOTE>
<BLOCKQUOTE>
Now regarding your example:
</BLOCKQUOTE>
<BLOCKQUOTE><BlockQuote>
The filenames you show here would normall be related
to regular files in the <TT>/etc/</TT> directory. However the
"permissions" you show suggest that these are block
device nodes (links to things like your <TT>/dev/hda1</TT>, etc).
</BlockQuote></BLOCKQUOTE>
<BLOCKQUOTE>
Moreover the ownership/group fields are rather
unlikely to be valid UIDs or GIDs on your system. This
suggests that you have a rather thoroughly corrupted
filesystem. So, my first suggestion would be to
boot from a clean rescue floppy and try '<tt>e2fsck -c</tt>'
Then consider re-installing Linux (after backing up any
data, of course).
</BLOCKQUOTE>
<!-- sig -->
<!-- end 5 -->
<!--startcut ======================================================= -->
<P> <hr> <P>
<H5 align="center"><a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 1999, James T. Dennis
<BR>Published in <I>The Linux Gazette</I> Issue 39 April 1999</H5>
<P> <hr> <P>
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
<TABLE WIDTH="96%"><TR VALIGN="center" ALIGN="center">
<TD ROWSPAN="2" WIDTH="30%"><A HREF="../lg_answer39.html"
><IMG SRC="../../gx/dennis/answernew.gif"
ALT="[ Answer Guy Index ]"></A></td>
<TD WIDTH="6%"><A HREF="2.html">2</A></TD>
<TD WIDTH="6%"><A HREF="3.html">3</A></TD>
<TD WIDTH="6%"><A HREF="4.html">4</A></TD>
<TD WIDTH="6%"><A HREF="5.html">5</A></TD>
<TD WIDTH="6%"><A HREF="6.html">6</A></TD>
<TD WIDTH="6%"><A HREF="7.html">7</A></TD>
<TD WIDTH="6%"><A HREF="8.html">8</A></TD>
<TD WIDTH="6%"><A HREF="9.html">9</A></TD>
<TD WIDTH="6%"><A HREF="10.html">10</A></TD>
<TD WIDTH="6%"><A HREF="11.html">11</A></TD>
</TR><TR VALIGN="center" ALIGN="center">
<TD><A HREF="12.html">12</A></TD>
<TD><A HREF="13.html">13</A></TD>
<TD><A HREF="15.html">15</A></TD>
<TD><A HREF="16.html">16</A></TD>
<TD><A HREF="18.html">18</A></TD>
<TD><A HREF="19.html">19</A></TD>
<TD><A HREF="21.html">21</A></TD>
<TD><A HREF="22.html">22</A></TD>
<TD><A HREF="23.html">23</A></TD>
</TR></TABLE>
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<P> <hr> <P>
<!-- begin lgnav ::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<A HREF="../index.html"
><IMG SRC="../../gx/indexnew.gif" ALT="[ Table Of Contents ]"></A>
<A HREF="../../index.html"
><IMG SRC="../../gx/homenew.gif" ALT="[ Front Page ]"></A>
<A HREF="../lg_bytes39.html"
><IMG SRC="../../gx/back2.gif" ALT="[ Previous Section ]"></A>
<A HREF="../lg_tips39.html"
><IMG SRC="../../gx/fwd.gif" ALT="[ Next Section ]"></A>
<!-- end lgnav ::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
</BODY></HTML>
<!--endcut ========================================================= -->