📄 rhl37.htm
字号:
<FONT COLOR="#000080">gzip -9 filename</FONT></PRE>
<P>The -9 option, which tells gzip to use the highest compression factor, will probably be the option you use the most. Alternatively, leave this option off and let gzip work with its default settings. A gzip compressed file has the extension .gz appended,
and the original file is deleted. To uncompress a gzipped file, use either the gunzip utility or gzip -d filename.
<BR>
<BR>
<A NAME="E68E323"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Using </B><B>tar</B></FONT></CENTER></H3>
<BR>
<P>The tar (tape archiver) utility has been used with UNIX systems for many years. Unfortunately, it's not very friendly and can be quite temperamental at times, especially when you're unfamiliar with the syntax required to make tar do something useful.
<BR>
<P>The tar program is designed to create a single archive file, much as the ZIP utilities do for DOS. With tar, you can combine many files into a single larger file, which makes it easier to move the collection or back it up to tape. The general syntax
used by tar is as follows:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar [options] [file]</FONT></PRE>
<P>The options available are lengthy and sometimes obtuse. Files can be specified with or without wildcards. A simple example of creating a tar archive file is
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cvf archive1.tar /usr/tparker</FONT></PRE>
<P>which combines all the files in /usr/tparker into a tar archive called archive1.tar. The c option tells tar to create the archive; the v tells it to be verbose, displaying messages as it goes; and the f tells it to use the filename archive1.tar as the
output file.
<BR>
<P>The extension .tar is not automatically appended by tar, but is a user convention that helps identify the file as an archive. This convention isn't widely used, though, although it should be as it helps identify the file.
<BR>
<P>The c option creates new archives. (If the file existed before, it is deleted.) The u (update) option is used to append new files to an existing archive, or to create the archive if it doesn't exist. This is useful if you keep adding files. The x option
is used to extract files from the archive. To extract with the tar command all the files in the archive in the earlier example, you would use the command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar xvf archive1.tar</FONT></PRE>
<P>There's no need to specify a filename, because the filenames and paths will be retained as the archive is unpacked. It's important to remember that the path is saved with the file. So if you archived /usr/tparker and then moved into /usr/tparker and
issued the extract command, the files would be extracted relevant to the current directory, which would place them in /usr/tparker/usr/tparker. You must be very careful to extract files properly. If you want to force a new directory path on extracted
files, a command-line option allows this.
<BR>
<P>The tar system does not remove the original files as they are packed into the archive, nor does it remove the archive file when files are extracted. These steps must be performed manually.
<BR>
<P>You can use tar to copy files to tapes or floppies by specifying a device name and the f option as a device name. To archive files in /usr/tparker to a floppy disk in the first drive, you could use the following command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cvf /dev/fd0 /usr/tparker</FONT></PRE>
<P>This can cause a problem if the floppy doesn't have enough capacity, however, so tar lets you specify the capacity with the k option. In this case, the command for a 1.44MB floppy is as follows:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cvfk /dev/fd0 1440 /usr/tparker</FONT></PRE>
<P>If the floppy is full before the entire archive has been copied, tar prompts you for another one. It's important to keep the arguments in the right order. You see that the f is before the k, so the device name must be before the capacity. All the
argument keyletters are gathered together instead of issued one at a time followed by their value, which is one aspect of tar that can be very confusing.
<BR>
<P>As a last issue for backing up to floppy, it is sometimes necessary to tell the tar program about the blocking used (blocking identifies how many blocks are used for each chunk of information on the device). A floppy usually has a blocking factor of 4,
so the command becomes the following:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar cvfkb /dev/fd0 1440 4 /usr/tparker</FONT></PRE>
<P>A final problem with tar is that it can't always handle a generic device such as /dev/fd0, and must be specifically told the disk type.
<BR>
<P>For more complete information on all the options used by tar, check the man pages or, even better, a good system administration book.
<BR>
<P>You can use tar to archive compressed files, too, in the same manner. You can also compress a tar file without any problems. In these cases, you might get filenames such as
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">filename.tar.gz</FONT></PRE>
<P>which show that you should run gunzip first to recover the tar file, and then run tar to extract the files in the archive. You can run the commands together with pipes:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">gunzip filename.tar.gz | tar xvf -</FONT></PRE>
<P>The hyphen as the tar filename after the pipe symbol is standard UNIX terminology for taking the input from the pipe (stdin).
<BR>
<BR>
<A NAME="E68E324"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Backups</B></FONT></CENTER></H3>
<BR>
<P>The three rules of system administration are back up, back up, and back up. This might sound silly and trite, but a backup can save you whenever you do something silly to the file system, or when problems occur. With UNIX, most backups are made to a
tape device using tar, although many Linux users don't have tape units available and have to resort to floppies.
<BR>
<P>Backups are made with the tar utility, as I mentioned earlier. The procedure is exactly the same as I showed you earlier. To back up the entire system on floppy, the command is
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar -cvfbk /dev/fd0 1440 4 /</FONT></PRE>
<P>To back up to a high-capacity tape device larger than the file system (and hence not needing a capacity limit) called /dev/rct0, the command is
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar -cvfk /dev/rct0 20 /</FONT></PRE>
<P>In many cases, you won't want to back up the entire system, because it's easier to reinstall off a CD-ROM. However, you should back up your user files by either backing up the entire /usr directory or specifically backing up your own home directory.
<BR>
<P>To restore a backup, you use the tar command again:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">tar -xvf /dev/rct0</FONT></PRE>
<P>This recovers all files from the tape device /dev/rct0. You can explicitly restore specific files if you need to.
<BR>
<P>Several commercial products offer automated backups, although you can do this quite easily with the cron command.
<BR>
<BR>
<A NAME="E68E325"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Setting Up Your System</B></FONT></CENTER></H3>
<BR>
<P>You can perform several little tasks to tweak or optimize your Linux system, although in many cases they are dependent on the version you are running and other applications coexisting. We can look at a few of the miscellaneous tasks here.
<BR>
<BR>
<A NAME="E69E421"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Setting the System Name</B></FONT></CENTER></H4>
<BR>
<P>The system name is contained in a file called /etc/HOSTNAME. It is simply the name the system calls itself for identification, which is especially useful if you are networking your Linux machine with others. You can call the system anything you want.
<BR>
<P>To set your system name (also called a host name), you can either edit the system files (which should be followed by a reboot to make the changes effective) or use the hostname command. The command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">hostname hellfire</FONT></PRE>
<P>sets the machine's name to hellfire.
<BR>
<BR>
<A NAME="E69E422"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Using a Maintenance Disk</B></FONT></CENTER></H4>
<BR>
<P>Every system should have a maintenance disk that enables you to check the root file system, recover from certain disk problems, and solve simple problems (such as forgetting your root password). The emergency disks, also called the boot/root floppies,
are created with the setup program in most distributions of Linux when the configuration is changed.
<BR>
<P>You can usually create an emergency boot disk from the CD-ROM that the system came on, as well as obtain the necessary files from FTP sites.
<BR>
<P>After you have booted your machine with the emergency disk, you can mount the disk partitions with the mount command.
<BR>
<BR>
<A NAME="E69E423"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Forgetting the </B><B>root</B><B> Password</B></FONT></CENTER></H4>
<BR>
<P>This is an embarrassing and annoying problem, but luckily one easily fixed with Linux. (If only other UNIX systems were so easy!) To recover from a problem with the root password, use a boot floppy and boot the system. Mount the root partition, and edit
the /etc/passwd file to remove any password for root; then, reboot from the hard disk.
<BR>
<P>After the system has booted, you can set a password again.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>This points out one major security problem with Linux: Anyone with a boot floppy can get unrestricted access to your system!</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E424"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Setting the Login Message</B></FONT></CENTER></H4>
<BR>
<P>If you have more than one user on the system, you can display information about the system, its maintenance, or changes in a file called /etc/motd (message of the day). The contents of this file are displayed whenever someone logs in.
<BR>
<P>To change the /etc/motd file, use any text editor and save the contents as ASCII. You can make the contents as long as you want, but readers usually appreciate brevity. The /etc/motd file is useful for informing users of downtime, backups, or new
additions. You can also use it to give a more personal feel to your system.
<BR>
<BR>
<A NAME="E68E326"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>
<BR>
<P><A NAME="I2"></A>System administration is not a complicated subject, unless you want to get into the nitty-gritty of your operating system and its configuration. For most Linux users who use the operating system for their personal experimentation, the
administration steps explained in this chapter should be sufficient for most purposes. If you want to get into more detail, check out a good UNIX system administration book.
<P ALIGN=LEFT>
<A HREF="rhl36.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl36.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A>
<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="rhl38.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl38.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -