📄 ch08.htm
字号:
</TABLE>
Therefore, a file permission of 751 means that the owner has read, write, and execute
permission (4+2+1=7), the group has read and execute permission (4+1=5), and others
have execute permission (1).</P>
<P>If you play with the numbers, you quickly see that the permission digits can range
between 0 and 7, and that for each digit in that range there's only one possible
combination of read, write, and execute permissions.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading38<FONT COLOR="#000077"><B>TIP:</B> </FONT>If you're familiar
with the binary system, think of <TT>rwx</TT> as a three-digit binary number. If
permission is allowed, the corresponding digit is 1. If permission is denied, the
digit is 0. So <TT>r-x</TT> would be the binary number 101, which is 4+0+1, or 5.
<TT>--x</TT> would be 001, which is 0+0+1, which is 1, and so on.
<HR>
</DL>
<P>The following combinations are possible: 0 or <TT>---</TT>: no permissions at
all</P>
<P>4 or <TT>r--</TT>: read-only</P>
<P>2 or <TT>-w-</TT>: write-only (rare)</P>
<P>1 or <TT>--x</TT>: execute</P>
<P>6 or <TT>rw-</TT>: read and write</P>
<P>5 or <TT>r-x</TT>: read and execute</P>
<P>3 or <TT>-wx</TT>: write and execute (rare)
<BLOCKQUOTE>
<P>7 or <TT>rwx</TT>: read, write, and execute
</BLOCKQUOTE>
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading39<FONT COLOR="#000077"><B>NOTE:</B> </FONT>Anyone who has
permission to read a file can then copy that file. When a file is copied, the copy
is owned by the person doing the copying. He or she can then change ownership and
permissions, edit the file, and so on.
<HR>
</DL>
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading40<FONT COLOR="#000077"><B>WARNING: </B></FONT>Removing write
permission from a file doesn't prevent the file from being deleted! It does prevent
it from being deleted accidentally, since Linux asks you whether you want to override
the file permissions. You have to answer <TT>y</TT>, or the file will not be deleted.
<HR>
</DL>
<CENTER>
<H4><A NAME="Heading41<FONT COLOR="#000077">Changing File Permissions</FONT></H4>
</CENTER>
<P>To change file permissions, use the <TT>chmod</TT> (change [file] mode) command.
The syntax is <TT>chmod <</TT>specification<TT>> </TT>file.</P>
<P>There are two ways to write the permission specification. One is by using the
numeric coding system for permissions:<FONT COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">darkstar:~$ ls -l myfile
-rw-r--r-- 1 fido users 114 Dec 7 14:31 myfile
darkstar:~$ chmod 345 myfile
darkstar:~$ ls -l myfile
--wxr--r-x 1 fido users 114 Dec 7 14:31 myfile
darkstar:~$ chmod 701 myfile
darkstar:~$ ls -l myfile
-rwx----x 1 root users 114 Dec 7 14:31 myfile
</FONT></PRE>
<P>This method has the advantage of specifying the permissions in an absolute, rather
than relative, fashion. Also, it's easier to tell someone, "Change permissions
on the file to seven- five-five" than to say, "Change permissions on the
file to read-write-execute, read-execute, read-execute."</P>
<P>You can also use letter codes to change the existing permissions. To specify which
of the per- missions to change, type <TT>u</TT> (user), <TT>g</TT> (group), <TT>o</TT>
(other), or <TT>a</TT> (all). This is followed by a + to add permissions or a - to
remove them. This in turn is followed by the permissions to be added or removed.
For example, to add execute permissions for the group and others, you would type<FONT
COLOR="#0066FF"></FONT>
<PRE><FONT COLOR="#0066FF">darkstar:~$ chmod go+r myfile
</FONT></PRE>
<P>Other ways of using the symbolic file permissions are described in the <TT>chmod</TT>
man page.
<CENTER>
<H4><A NAME="Heading42<FONT COLOR="#000077">Changing Directory Permissions</FONT></H4>
</CENTER>
<P>You change directory permissions with <TT>chmod</TT>, exactly the same way as
with files. Remember that if a directory doesn't have execute permissions, you can't
<TT>cd</TT> to it.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading43<FONT COLOR="#000077"><B>WARNING: </B></FONT>Any user who
has write permission in a directory can delete files in that directory, whether or
not that user owns or has write privileges to those files. Most directories, therefore,
have permissions set to <TT>drwxr-xr-x</TT>. This ensures that only the directory's
owner can create or delete files in that directory. It is especially dangerous to
give write permission to all users for directories!
<HR>
</DL>
<CENTER>
<H3><A NAME="Heading44<FONT COLOR="#000077">Miscellaneous File Commands</FONT></H3>
</CENTER>
<P>There are many Linux commands to manipulate files, directories, and the entire
file system. Many of these commands are used only by system administrators. You will
touch on a few that are also used by ordinary users. These and other important system
administrator commands are further detailed in Chapter 38, "System Administration
Basics."
<CENTER>
<H4><A NAME="Heading45<FONT COLOR="#000077">Fear of Compression: The Zipless
File</FONT></H4>
</CENTER>
<P>Most Linux files are stored on the installation CD-ROM in compressed form. This
allows more information to be stored.</P>
<P>When you installed Linux, the installation program uncompressed many of the files
it transferred to your hard drive. However, if you look, you will be able to find
compressed files!</P>
<P>Any file ending in .gz--for example, <TT>squashed.gz</TT>--is a compressed file.
To uncompress this particular type of file, type <TT>gunzip <</TT>file<TT>></TT>.
For this example, you would type <TT>gunzip squashed.gz</TT>. The <TT>gunzip</TT>
program creates an uncompressed file and removes the .gz extension. Therefore, you
would wind up with a normal file called <TT>squashed</TT>.</P>
<P>To compress a file, use the <TT>gzip</TT> command. Typing <TT>gzip squashed</TT>
would compress <TT>squashed</TT> and rename it <TT>squashed.gz</TT>.</P>
<P>Another type of compressed file you might see ends with the extension .zip. Use
<TT>unzip</TT> to uncompress these files. To create files of this type, use <TT>zip</TT>.
<CENTER>
<H4><A NAME="Heading46<FONT COLOR="#000077">How to tar Without Feathering</FONT></H4>
</CENTER>
<P>In almost any location with several Linux or UNIX systems, sooner or later you
will hear someone say, "Put that in a <TT>tar</TT> file and send it over."</P>
<P>They are referring to the output created by the <TT>tar</TT> program. Although
<TT>tar</TT> stands for tape archive, it can copy files to floppy disk or to any
filename you specify in the Linux file system. The <TT>tar</TT> command is used because
it can archive files and directories into a single file and then recreate the files
and even the directory structures later. It's also the easiest way to place Linux
files on a floppy disk.</P>
<P>To create a <TT>tar</TT> file, you typically type <TT>tar cvf <</TT>destination<TT>></TT>
<TT><</TT>files/directories<TT>></TT>, where files/directories specifies the
files and directories to be archived, and destination is where you want the <TT>tar</TT>
file to be created. If you want the destination to be a floppy disk, you usually
type <TT>/dev/fd0</TT> as the destination. This specifies your primary floppy drive
(A: in MS-DOS). You can use a floppy disk that's been formatted under MS-DOS.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading47<FONT COLOR="#000077"><B>WARNING:</B> </FONT>When <TT>tar</TT>
archives to a floppy disk, all the data already on the disk is destroyed. You have
to reformat it to use it with MS-DOS again.
<HR>
</DL>
<P>To extract a <TT>tar</TT> file, you typically type <TT>tar xvf <</TT>tar file<TT>></TT>.
For instance, to pull files from a floppy disk, you would type <TT>tar xvf /dev/fd0</TT>.
<DL>
<DT></DT>
</DL>
<DL>
<DD>
<HR>
<A NAME="Heading48<FONT COLOR="#000077"><B>NOTE: </B></FONT>Unlike <TT>zip</TT>
and <TT>gzip</TT>, <TT>tar</TT> doesn't remove, delete, or rename the files it puts
into the archive. However, when <TT>tar</TT> extracts archived files, it overwrites
existing files with files of the same name from the archive.
<HR>
</DL>
<CENTER>
<H3><A NAME="Heading49<FONT COLOR="#000077">Important Directories in the Linux
File System</FONT></H3>
</CENTER>
<P>Most of the directories that hold Linux system files are "standard."
Other UNIX systems will have identical directories with similar contents. This section
summarizes some of the more important directories on your Linux system.
<CENTER>
<H4><A NAME="Heading50<FONT COLOR="#000077">/</FONT></H4>
</CENTER>
<P>This is the root directory. It holds the actual Linux program, as well as subdirectories.
Do not clutter this directory with your files!
<CENTER>
<H4><A NAME="Heading51<FONT COLOR="#000077">/home</FONT></H4>
</CENTER>
<P>This directory holds users' home directories. In other UNIX systems, this can
be the <TT>/usr</TT> or <TT>/u</TT> directory.
<CENTER>
<H4><A NAME="Heading52<FONT COLOR="#000077">/bin</FONT></H4>
</CENTER>
<P>This directory holds many of the basic Linux programs. <TT>bin</TT> stands for
binaries, files that are executable and that hold text only computers could understand.
<CENTER>
<H4><A NAME="Heading53<FONT COLOR="#000077">/usr</FONT></H4>
</CENTER>
<P>This directory holds many other user-oriented directories. Some of the most important
are described in the following sections. Other directories found in <TT>/usr</TT>
include <TT>docs</TT> Various documents, including useful Linux information.</P>
<P><TT>man</TT> The man pages accessed by typing <TT>man <</TT>command<TT>></TT>.
<BLOCKQUOTE>
<P><TT>games</TT> The fun stuff!
</BLOCKQUOTE>
<CENTER>
<H4><A NAME="Heading54<FONT COLOR="#000077">/usr/bin</FONT></H4>
</CENTER>
<P>This directory holds user-oriented Linux programs.
<CENTER>
<H4><A NAME="Heading55<FONT COLOR="#000077">/usr/spool</FONT></H4>
</CENTER>
<P>This directory has several subdirectories. <TT>mail</TT> holds mail files, <TT>spool</TT>
holds files to be printed, and <TT>uucp</TT> holds files copied between Linux machines.
<CENTER>
<H4><A NAME="Heading56<FONT COLOR="#000077">/dev</FONT></H4>
</CENTER>
<P>Linux treats everything as a file! The <TT>/dev</TT> directory hold devices. These
are special files that serve as gateways to physical computer components. For instance,
if you copy to <TT>/dev/fd0</TT>, you're actually sending data to the system's floppy
disk. Your terminal is one of the <TT>/dev/tty</TT> files. Partitions on the hard
drive are of the form <TT>/dev/hd0</TT>. Even the system's memory is a device!</P>
<P>A famous device is <TT>/dev/null</TT>. This is sometimes called the bit bucket.
All information sent to <TT>/dev/null</TT> vanishes--it's thrown into the trash.
<CENTER>
<H4><A NAME="Heading57<FONT COLOR="#000077">/usr/sbin</FONT></H4>
</CENTER>
<P>This directory holds system administration files. If you do an <TT>ls -l</TT>,
you see that you must be the owner, r
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -