📄 311-314.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Understanding the File and Directory System</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=16//-->
<!--PAGES=311-314//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="308-310.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="314-316.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>These permission subfields can show more information; in fact, several attributes are packed into these three fields. Unfortunately, what these attributes mean is determined by the version of Linux you use and whether the file is executable.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>Normally, a running program is owned by whoever ran it. If the user ID bit is on, the running program is owned by the owner of the file. This means that the running program has all the permissions of the owner of the file. If you’re an ordinary user and the running program is owned by the root user, that running program has automatic permission to read and write any file in the system regardless of your permissions. The same is true of the set group ID bit.<HR></FONT>
</BLOCKQUOTE>
<P>The <I>sticky bit</I> can also be set in these subfields. The sticky bit tells the system to save a copy of a running program in memory after the program completes. If the program is used often, the sticky bit can save the system a little time the next time it runs the program because the program doesn’t have to be reloaded into memory from disk each time someone runs it.</P>
<P>You can change permissions on any file you have write permission for by using the <TT>chmod</TT> command. This command has two different syntaxes: absolute and relative. With absolute permissions, you define exactly what the permissions on a file will be in octal, or base 8. An octal number can have a value from 0 to 7. UNIX was originally created on a series of DEC minicomputers that used the octal numbering system, hence the current use of octal numbers. The octal numbers are added together to arrive at a number that defines the permissions. Table 16.3 lists the valid octal permissions.</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 16.3</B> Absolute Octal Permissions Used with the chmod Command
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="20%" ALIGN="LEFT">Octal Value
<TH WIDTH="80%" ALIGN="LEFT">Permissions Granted
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD>0001
<TD>Execute permission for the owner
<TR>
<TD>0002
<TD>Write permission for the owner
<TR>
<TD>0004
<TD>Read permission for the owner
<TR>
<TD>0010
<TD>Execute permission for the group
<TR>
<TD>0020
<TD>Write permission for the group
<TR>
<TD>0040
<TD>Read permission for the group
<TR>
<TD>0100
<TD>Execute permission for all others
<TR>
<TD>0200
<TD>Write permission for all others
<TR>
<TD>0400
<TD>Read permission for all others
<TR>
<TD>1000
<TD>Sticky bit on
<TR>
<TD VALIGN="TOP">2000
<TD>Group ID bit on if the file is executable; otherwise, mandatory file locking is on
<TR>
<TD>4000
<TD>User ID bit on if the file is executable
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<P>Group and user IDs refer to who has permission to use, read, or execute a file. These initial file permissions are granted by the systems administrator when the user’s account is first created. Only users of an indicated group can access files in a group, and only if the user has given group members permission to those files.
</P>
<P>To give a file read and write permissions for everyone, you must add the required permissions together, as in the following example:</P>
<CENTER>
<TABLE WIDTH="70%"><TR>
<TD WIDTH="30%">0002
<TD WIDTH="70%">Write permission for the owner
<TR>
<TD>0004
<TD>Read permission for the owner
<TR>
<TD>0020
<TD>Write permission for the group
<TR>
<TD>0040
<TD>Read permission for the group
<TR>
<TD>0200
<TD>Write permission for all others
<TR>
<TD>0400
<TD>Read permission for all others
<TR>
<TD COLSPAN="2"><HR>
<TR>
<TD>0666
<TD>Read and write permission for everyone
</TABLE>
</CENTER>
<P>To give a file these permissions, you would use the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
chmod 666 file
</PRE>
<!-- END CODE SNIP //-->
<P>Relative permissions use a slightly different format. With relative permissions, you must state the following:
</P>
<DL>
<DD><B>•</B> Whom you’re giving permissions to
<DD><B>•</B> What operation you intend (add, subtract, or set permissions)
<DD><B>•</B> What the permissions are
</DL>
<P>For example, if you type <B><TT>chmod a=rwx file</TT></B>, you give read, write, and execute permission to all users. Table 16.4 summarizes the commands for relative permissions.</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 16.4</B> Relative Permissions Used with the chmod Command
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="15%" ALIGN="LEFT">Value
<TH WIDTH="85%" ALIGN="LEFT">Description
<TR>
<TD COLSPAN="2"><HR>
<TR>
<TH ALIGN="LEFT">Whom
<TH>
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD>a
<TD>All users (the user, their group, and all others)
<TR>
<TD>g
<TD>Owner’s group
<TR>
<TD>o
<TD>All others not in the file’s group
<TR>
<TD>u
<TD>Just the user
<TR>
<TH ALIGN="LEFT" COLSPAN="2">Operator
<TR>
<TD COLSPAN="2"><HR>
<TR>
<TD>+
<TD>Adds the mode
<TR>
<TD>-
<TD>Removes the mode
<TR>
<TD>=
<TD>Sets the mode absolutely
<TR>
<TH ALIGN="LEFT" COLSPAN="2">Permission
<TR>
<TD COLSPAN="2"><HR>
<TR>
<TD>x
<TD>Sets execute
<TR>
<TD>r
<TD>Sets read
<TR>
<TD>w
<TD>Sets write
<TR>
<TD>s
<TD>Sets user ID bit
<TR>
<TD>t
<TD>Sets sticky bit
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<P>If a file has been marked as having the user ID bit on, the permissions displayed by the <TT>ls -l</TT> command look like this:</P>
<!-- CODE SNIP //-->
<PRE>
-rws------ 1 sglines 3136 Jan 17 15:42 x
</PRE>
<!-- END CODE SNIP //-->
<P>If the group ID bit is added, the permissions look like this:
</P>
<!-- CODE SNIP //-->
<PRE>
-rws--S--- 1 sglines 3136 Jan 17 15:42 x
</PRE>
<!-- END CODE SNIP //-->
<P>If you then turn on the sticky bit for the file, the permissions look like this:
</P>
<!-- CODE SNIP //-->
<PRE>
-rws--S--rws--S--T 1 sglines 3136 Jan 17 15:42 x
</PRE>
<!-- END CODE SNIP //-->
<P>Note the use of uppercase <TT>S</TT> and <TT>T</TT> to indicate the status of the user ID bit and the sticky bit, respectively.</P>
<H3><A NAME="Heading10"></A><FONT COLOR="#000077">Linux Standard Directories</FONT></H3>
<P>You’re already familiar with the concept of directories. When you log in, the system places you in your home directory. The <TT>PATH</TT> environment variable is set to point to other directories that contain executable programs. These other directories are part of the standard Linux directory structure.</P>
<P>There is the classic set of directories for UNIX and what can be called the “emerging standard set of directories,” which Linux basically follows. These are described in the following sections.</P>
<H4 ALIGN="LEFT"><A NAME="Heading11"></A><FONT COLOR="#000077">Classic UNIX Directories</FONT></H4>
<P>Before UNIX System V Release 4 (for example, UNIX System V Release 3.2 and earlier), most versions of UNIX settled on a regular system of organizing the UNIX directories that looked like this:
</P>
<!-- CODE //-->
<PRE>
/
/etc
/lib
/tmp
/bin
/usr
/spool
/bin
/include
/tmp
/adm
/lib
</PRE>
<!-- END CODE //-->
<P>The /etc directory contains most of the system-specific data required to boot, or bring the system to life. It contains such files as passwd and inittab, which are necessary for the proper operation of the system.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="308-310.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="314-316.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -