⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch38.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 3 页
字号:


compression required, the longer it takes to compress). To use <TT>gzip</TT>, specify



the filename to be compressed and the compression type:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">gzip -9 filename



</FONT></PRE>



<P>The <TT>-9</TT> option, which tells <TT>gzip</TT> to use the highest compression



factor, will probably be the option you use the most. Alternatively, leave this option



off and let <TT>gzip</TT> work with its default settings. A <TT>gzip</TT> compressed



file has the extension <TT>.gz</TT> appended, and the original file is deleted. To



uncompress a <TT>gzipp</TT>ed file, use the <TT>gunzip</TT> utility.



<H3 ALIGN="CENTER"><A NAME="Heading16<FONT COLOR="#000077">Using tar</FONT></H3>



<P>The <TT>tar</TT> (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 <TT>tar</TT> do



something useful.</P>



<P>The <TT>tar</TT> program is designed to create a single archive file, much as



the ZIP utilities do for DOS. With <TT>tar</TT>, 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 <TT>tar</TT> is as follows:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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 <TT>tar</TT> archive file



is<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">tar cvf archive1.tar /usr/tparker



</FONT></PRE>



<P>which combines all the files in <TT>/usr/tparker</TT> into a <TT>tar</TT> archive



called <TT>archive1.tar</TT>. The <TT>c</TT> option tells <TT>tar</TT> to create



the archive; the <TT>v</TT> tells it to be verbose, displaying messages as it goes;



and the <TT>f</TT> tells it to use the filename <TT>archive1.tar</TT> as the output



file.</P>



<P>The extension <TT>.tar</TT> is not automatically appended by <TT>tar</TT>, 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.</P>



<P>The <TT>c</TT> option creates new archives. (If the file existed before, it is



deleted.) The <TT>u</TT> (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 <TT>x</TT> option is used to extract files from the archive. To



extract with the <TT>tar</TT> command all the files in the archive in the earlier



example, you would use the command<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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 <TT>/usr/tparker</TT> and then moved into



<TT>/usr/tparker</TT> and issued the <TT>extract</TT> command, the files would be



extracted relevant to the current directory, which would place them in <TT>/usr/tparker/usr/tparker</TT>.



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.</P>



<P>The <TT>tar</TT> 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.</P>



<P>You can use <TT>tar</TT> to copy files to tapes or floppies by specifying a device



name and the <TT>f</TT> option as a device name. To archive files in <TT>/usr/tparker</TT>



to a floppy disk in the first drive, you could use the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">tar cvf /dev/fd0 /usr/tparker



</FONT></PRE>



<P>This can cause a problem if the floppy doesn't have enough capacity, however,



so <TT>tar</TT> lets you specify the capacity with the <TT>k</TT> option. In this



case, the command for a 1.44MB floppy is as follows:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">tar cvfk /dev/fd0 1440 /usr/tparker



</FONT></PRE>



<P>If the floppy is full before the entire archive has been copied, <TT>tar</TT>



prompts you for another one. It's important to keep the arguments in the right order.



You see that the <TT>f</TT> is before the <TT>k</TT>, 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 <TT>tar</TT>



that can be very confusing. As a last issue for backing up to floppy, it is sometimes



necessary to tell the <TT>tar</TT> 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:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">tar cvfkb /dev/fd0 1440 4 /usr/tparker



</FONT></PRE>



<P>A final problem with <TT>tar</TT> is that it can't always handle a generic device



such as <TT>/dev/fd0</TT>, and must be specifically told the disk type. For more



complete information on all the options used by <TT>tar</TT>, check the man pages



or, even better, a good system administration book. You can use <TT>tar</TT> to archive



compressed files, too, in the same manner. You can also compress a <TT>tar</TT> file



without any problems. In these cases, you might get filenames such as<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">filename.tar.gz



</FONT></PRE>



<P>which show that you should run <TT>gunzip</TT> first to recover the <TT>tar</TT>



file, and then run <TT>tar</TT> to extract the files in the archive. You can run



the commands together with pipes:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">gunzip filename.tar.gz | tar xvf -



</FONT></PRE>



<P>The hyphen as the <TT>tar</TT> filename after the pipe symbol is standard UNIX



terminology for taking the input from the pipe (<TT>stdin</TT>).



<H3 ALIGN="CENTER"><A NAME="Heading17<FONT COLOR="#000077">Backups</FONT></H3>



<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 <TT>tar</TT>, although many Linux users don't have tape units



available and have to resort to floppies.</P>



<P>Backups are made with the <TT>tar</TT> 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<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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 <TT>/dev/rct0</TT>, the command is<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">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 <TT>/usr</TT> directory or specifically backing up your own



home directory.</P>



<P>To restore a backup, you use the <TT>tar</TT> command again:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">tar xvf /dev/rct0



</FONT></PRE>



<P>This recovers all files from the tape device <TT>/dev/rct0</TT>. You can explicitly



restore specific files if you need to.</P>



<P>Several commercial products offer automated backups, although you can do this



quite easily with the <TT>cron</TT> command.



<H3 ALIGN="CENTER"><A NAME="Heading18<FONT COLOR="#000077">Setting Up Your



System</FONT></H3>



<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.



<H4 ALIGN="CENTER"><A NAME="Heading19<FONT COLOR="#000077">Setting the System



Name</FONT></H4>



<P>The system name is contained in a file called <TT>/etc/HOSTNAME</TT>. 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.</P>



<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 <TT>hostname</TT> command. The following command sets the machine's name to <TT>hellfire</TT>:<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">hostname hellfire



</FONT></PRE>



<H4 ALIGN="CENTER"><A NAME="Heading20<FONT COLOR="#000077">Using a Maintenance



Disk</FONT></H4>



<P>Every system should have a maintenance disk that enables you to check the <TT>root</TT>



file system, recover from certain disk problems, and solve simple problems (such



as forgetting your <TT>root</TT> 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. 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. After you have booted your machine with the emergency disk, you can mount



the disk partitions with the <TT>mount</TT> command.



<H4 ALIGN="CENTER"><A NAME="Heading21<FONT COLOR="#000077">Forgetting the root



Password</FONT></H4>



<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 <TT>root</TT> password, use a boot floppy and boot the system. Mount the <TT>root</TT>



partition, and edit the <TT>/etc/passwd</TT> file to remove any password for <TT>root</TT>;



then, reboot from the hard disk.</P>



<P>After the system has booted, you can set a password again.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading22<FONT COLOR="#000077"><B>WARNING: </B></FONT>This points



	out one major security problem with Linux: Anyone with a boot floppy can get unrestricted



	access to your system! On some systems, you can avoid this problem by setting the



	system BIOS to require a password before booting from a floppy drive.



<HR>







</DL>







<H4 ALIGN="CENTER"><A NAME="Heading23<FONT COLOR="#000077">Setting the Login



Message</FONT></H4>



<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 <TT>/etc/motd</TT> (message



of the day). The contents of this file are displayed whenever someone logs in.</P>



<P>To change the <TT>/etc/motd</TT> 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 <TT>/etc/motd</TT> 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.



<H3 ALIGN="CENTER"><A NAME="Heading24<FONT COLOR="#000077">Summary</FONT></H3>



<P>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.



















</td>
</tr>
</table>

<!-- begin footer information -->



</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -