📄 212-215.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Configuration and Installation:Basic Linux Tools</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=1558285660//-->
<!--TITLE=Linux Configuration and Installation//-->
<!--AUTHOR=Patrick Volkerding//-->
<!--AUTHOR=Kevin Reichard//-->
<!--AUTHOR=Eric Foster//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=4//-->
<!--PAGES=212-215//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="208-212.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="215-218.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Changing Ownerships and Permissions</FONT></H4>
<P>In the act of creating a file or directory, you automatically assign permissions to the file or directory. To see what permissions are the default, use the <B>umask</B> command:</P>
<!-- CODE SNIP //-->
<PRE>
$ umask
744
</PRE>
<!-- END CODE SNIP //-->
<P>This means that the owner of the file has full privileges, while your group and the world have the ability to read the file. To change this permission, you’ll again use the <B>umask</B> command, listing a new permission on the command line:</P>
<!-- CODE SNIP //-->
<PRE>
$ umask 007
</PRE>
<!-- END CODE SNIP //-->
<P>This may look odd, and indeed it is odd. The <B>umask</B> command changes permissions relative to a baseline of 777. The input to the <B>umask</B> command is therefore subtracted from the baseline 777, leaving you with the total of 770, meaning that the owner of the file and the group have full permissions to the file, while the rest of the world has no permissions at all.</P>
<P>In the same way, you’re automatically the owner of a file when you create it, but there may be times when you want to transfer this ownership to another user. You can do so with the <B>chown</B> command, provided you’re logged in the system as the root user. (You didn’t think you could change the ownership logged in as an ordinary user, did you? If <I>anyone</I> could change the ownership of a file, security in the UNIX operating system would be nonexistent.) When using the <B>chown</B> (short for change ownership, by the way) command, you list the new owner of the command and the file in question:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:~$ chown pat report
</PRE>
<!-- END CODE SNIP //-->
<P>You can also transfer ownership of an entire directory by using the -<I>R</I> option to the <B>chown</B> command:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:~$ chown -R pat reports_1996
</PRE>
<!-- END CODE SNIP //-->
<P>Similarly, the <B>chgrp</B> command changes group ownership of a file, listing the new group membership and the file in question:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:~$ chgrp linux_book chap4
</PRE>
<!-- END CODE SNIP //-->
<P><FONT SIZE="+1"><B>The Sticky Bit</B></FONT></P>
<P>In our continuing obsession with security, we present information about the sticky bit. In the past, UNIX hackers used to get around file permissions by messing with entire directories, as most system administrators would forget to set restrictive permissions for the directory itself.
</P>
<P>The sticky bit was a response to this security problem. Linux allows you to set the sticky bit, which makes a directory impregnable to everyone but the owner of a directory and the root user. To set the sticky bit, use the <B>chmod</B> command in the following manner:</P>
<!-- CODE SNIP //-->
<PRE>
gilbert:/$ chmod +t <I>directoryname</I>
</PRE>
<!-- END CODE SNIP //-->
<P>Once the sticky bit is set, no one (except the root user and the owner of the directory) has the ability to move or delete files in a directory, no matter what permissions are associated with a file.
</P>
<H3><A NAME="Heading14"></A><FONT COLOR="#000077">Dealing with Files and Directories</FONT></H3>
<P>We’ve thrown around the term <I>command</I> a great deal without ever really defining it (our copy editor is probably gnawing her red pen by this point), but we’re assuming you know what a command is and how you give a command to the computer. And you also know that the combination of a command and any options is called a <I>command line</I>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>Under Linux, commands can be run at a command line or under the X Window System in an <B>xterm</B> window (which we covered in Chapter 3). However, there are some cases when there’s an X Window version of the UNIX command; for example, there’s a version of <B>man</B> for the X Window System, called <B>xman</B>, that you should use instead. In this chapter, we’ll also note the X Window version.<HR></FONT>
</BLOCKQUOTE>
<P>If you’ve used MS-DOS for any extended period, you’ll instantly recognize the Linux counterparts presented here. If you’ve used Microsoft Windows for an extended period and have been hidden from the command line, you may be somewhat confused initially when you run through this series of Linux commands. And if you’re a UNIX workstation user, you’ll find that there might be slight differences between the commands/options and the version of UNIX you’re used to working with. (If you’re a Cray supercomputer user, you’re <I>really</I> slumming.)</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>This section will touch only on the most basic and useful Linux commands. For a more complete listing of Linux commands, check out <I>Linux in Plain English</I>—coming out shortly—or <I>teach yourself . . . UNIX, Third Edition</I> (MIS:Press) both listed in Appendix A.<HR></FONT>
</BLOCKQUOTE>
<P>You’ve already learned about the <B>cd</B> and <B>pwd</B> commands, which are used to move between directories and print the working directory, respectively. There are many more Linux commands used to deal with directories and files.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="208-212.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="215-218.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 + -